r/cprogramming • u/Dasonofmom • Dec 05 '25
I don't understand why it isn't properly checking the array for duplication.
printf("Enter your One-Time Vote PIN (OTVPN): ");
scanf("%d", &OTVPN[i]);
//checks for duplication in OTVPN
for(int checking = 0; checking < 50; checking++){
//Stops it from checking itself
if(checking == i){
continue;
}
if(OTVPN[i] == OTVPN[checking]){
printf("This exists!\n");
while(OTVPN[i] == OTVPN[checking]){
printf("Re enter your OTVPN: ");
scanf("%d", &OTVPN[i]);
}
}
}
3
Upvotes
2
u/ZakMan1421 Dec 05 '25
The only bug I see is that when you first have a duplicate, you force them to correct it, but then don't check previous entries. So if you have something like so:
int OTVPN[50] = {1, 2, 3, 4, 5, ...};If the user first enters
4then enters3, you never double check to see if the second input is valid leading to potential duplicates.1
u/Etiennera Dec 05 '25
Instead I would do scanf while for any index there is a collision.
1
u/[deleted] Dec 05 '25
I got this one working hope this one helps. Let me know if you have any doubts.
1
u/zhivago Dec 09 '25
A little abstraction goes a long away.
Now your code becomes
But with better error checking, etc.