I have a given array and I need to determine how to find the number of duplicates in it. I have to do this using nested for loops and can not use vectors. I have tried it so far and I get 3, but the answer should be 2 since only the numbers 4 and 7 repeat. I see why I am getting 3 since it checks 4 two times but I can't seem to figure out how to adjust it so It never checks 4 again once it found a match.
#include <iostream>
using namespace std;
int main() {
const int num_elements = 12;
int numbers[num_elements] = { 2, 6, 7, 4, 5, 4, 1, 8, 9, 0, 7, 4 };
unsigned int numduplicates = 0;
for(int i = 0; i < num_elements; ++i){
int oneCounterMax = 0;
for(int j = i + 1; j < num_elements; ++j) {
if((numbers[i] == numbers[j]) && (oneCounterMax < 1)) {
++numduplicates;
++oneCounterMax;
}
}
}
cout << numduplicates << endl;
}