I’m trying to search through an array and print out the only number within it which doesn’t have a pair, so in this case '4'.

The result keeps coming up as 2 so even though I feel I have the logic correct, I am definitely overlooking something.

I've been trying to solve this for a while and keep getting stuck

Many thanks in advance.

Here's the code:

```

int main(){
    int arr[] = {1, 1, 2, 2, 3, 3, 4};
    int n = sizeof(arr)/sizeof(*arr);
    int foundNum = 0;
    int counter = 0;

    while(counter !=n) {
        int i = 0;
        if (arr[i] != arr[i + 1]) {
            foundNum = arr[i];
        } else {
            arr[i] = arr[i+2];
        }
        counter += 1;
    }
    std::cout << foundNum;
    return 0;
}

```