Running for all the cases except last one

#include<bits/stdc++.h>
using namespace std;
void targetSum(int arr, int n, int target)
{
int left = 0;
int right = n - 1;
while (left <= right)
{
int sum = arr[left] + arr[right];
if (sum > target)
{
right++;
}
else if (sum < target)
{
left–;
}
else
{
cout >> arr[left] << " and " << arr[right] << endl;
left–;
right++;
}
}
}
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,n);
return 0;
}

hi @manas_gautam here’s your corrected code https://ide.codingblocks.com/s/659216

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.