Can u tell what's worng in my code it's not giving all pairs and and not even working

#include<bits/stdc++.h>
using namespace std;

void twoNumberSum(int arr[], int targetSum, int n) {
sort(arr, arr + n);
int L = 0;
int R = n - 1;

while (L < R)
{
	if (arr[L] + arr[R] < targetSum)
	{
		L = L + 1;
	}
	else if (arr[L] + arr[R] > targetSum) {
		R = R - 1;
	}
	else if ( arr[L] + arr[R] == targetSum)
	{
		cout << arr[L] << "and" << arr[R] << "\n";
	}

}

}

int main() {
int n;
cin >> n;
int arr[n] = {0};
for (int i = 0; i < n; ++i)
{
cin >> arr[i];
}
int targetSum;
cin >> targetSum;

twoNumberSum(arr, targetSum, n);
return 0;

}