Where is the error in my code .why all test cases are not getting passed ,only 25 out of 100 are getting passed

#include<bits/stdc++.h>
using namespace std;
void targetSum(int arr[], int n, int target)
{
int i= 0;
int j = n - 1;
while (i <j)
{
int sum = arr[i] + arr[j];
if (sum > target)
{
j–;
}
else if (sum < target)
{
i++;
}
else
{
cout <<arr[i]<<" and "<< arr[j]<<endl;
j–;
i++;
}
}
}
int main() {
int N;
cin>>N;
int arr[N];
for(int i=0;i<N;i++){
cin>>arr[i];
}
int x;
cin>>x;
targetSum(arr,N,x);
return 0;
}