Why am i getting wrong answer

#include
#include <bits/stdc++.h>
using namespace std;
void sum(int n)
{
int a[100],t;
for( int i=0;i<n;i++)
{
cin>>a[i];

}
int s=sizeof(a)/sizeof(a[0]);
sort(a,a+s);
cout<<"Target vaue:";
cin>>t;

int i=0;
int j=n;
while(i<j)	
	{	
		if(a[i]+a[j]>t)
		{
			j--;
		}
		if(a[i]+a[j]<t)
		{
			i++;
			
		}
		if(a[i]+a[j]==t)
		{
			cout<<i<<"and"<<j;
		}
		else
		{
			cout<<"Target sum not acheived";
		}

	}

}
int main() {

int n;
cout<<"No. of element\n";
cin>>n;
sum(n);
return 0;

}

Please save your code on ide.codingblocks.com and then share its link.

You output must match exactly with the sample output given in the question.
Check now:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.