Target Sum Pairs Problem

Half test cases failed, please help!

#include<iostream>
using namespace std;
void targetsumpair(int arr[], int n, int target){
for(int i=0;i<n;i++){

for(int j=i+1;j<n;j++){

if(target==arr[i]+arr[j]){

                cout<<arr[i]<<" and "<<arr[j]<<endl;

}

}

}

}

int main(){

int n;

    cin>>n;

int arr[100];

for(int i=0;i<n;i++){

        cin>>arr[i];

}

int target;

    cin>>target;

int left, right;

    left=0;

    right=n;

while(left<right){

if(arr[left]+arr[right]==target){

            cout<<arr[left]<<" and "<<arr[right]<<endl;

            left++;

}

else{

            right--;

}

}

return 0;

}