I am having problems getting my matches counter to work properly. The program is meant to simulate a bingo game. When a number is matched, the counter should go up by one.. instead, it often increases by two or three, claiming that other locations in the array equal the number being checked.

I believe the problem lies in the logic of my for loops:

Code:

for (a = 0; a < 3; a++){ /* a is y dimension of array being checked */
for (b = 0; b < 9; b++){ /* b is x dimension of array being checked */
if (Bingo_Numbers[x] == Bingo_Card[a][b]){
Match_Count++;
printf ("Match on number %2d\n", Bingo_Numbers[x]);
printf ("You now have %2d numbers left to match!\n", 15 - Match_Count);
printf ("Bingo Card Location x: %d y: %d\n", b,a);
}
}
}
}

here is the full source code so you can see where the variables are coming from:

Code:

/* Draws the bingo numbers */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main(void)
{
int Bingo_Card[9][3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18,
81, 82, 83, 84, 85, 86, 87, 88, 0 };
int Bingo_Numbers[90];
int Random;
int x = 0;
int y;
int a,b,c;
int Match_Count = 0;
srand((unsigned)time(NULL));
for (c = 0; Match_Count < 15; x++){ /*Matching Numbers Loop*/
printf ("\nPress any key to draw another number");
getche();
Random = rand() % 90 + 1;
for (y = 0; y < 90; ){
if (Random == Bingo_Numbers[y])
{
Random = rand() % 90 + 1;
y = 0;
}
else y++;
}
Bingo_Numbers[x] = Random;
printf ("\nDrawn Number %2d: %2d\n", x + 1, Bingo_Numbers[x]);
for (a = 0; a < 3; a++){ /* a is y dimension of array being checked */
for (b = 0; b < 9; b++){ /* b is x dimension of array being checked */
if (Bingo_Numbers[x] == Bingo_Card[a][b]){
Match_Count++;
printf ("Match on number %2d\n", Bingo_Numbers[x]);
printf ("You now have %2d numbers left to match!\n", 15 - Match_Count);
printf ("Bingo Card Location x: %d y: %d\n", b,a);
}
}
}
}
printf ("BINGO!");
}