Bingo Game

Uhm, so hello! We have this project in our CS course that states that we have to generate our own Bingo Game program, we can use help or we can let a person/people work on it as long as we can understand it. But I chose the latter part of doing it with my partner, but by just asking for help. So here it is, I have this code for generating a card in a bingo game. It has a range, e.g. (B=1-15, I=16=30.....) until O that's until the number 75 only. It's already fixed, the only problem is that when I generate a number in the column B, and the other columns as well, the numbers are repeating. I've spent a day to 3 thinking and experimenting on my program, but still it repeats the number on a column! Uhh, can you guys help me with these? I'm a beginner, thank you! I also tried putting it in variables, and validating it one-by-one, but still it doesn't work. :(
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include<iostream>
#include<ctime>
#include<conio.h>
using namespace std;
void main()
{

	int num[5][5],row,col,a,b,c,d,e;
	int ask;
	
	srand(time(NULL));

	do{
		
		system("cls");
			cout<<"\n\n\t\t\t\t    BINGO GAME"<<endl;
	for(row=0;row<5;row++)
		for(col=0;col<5;col++)
			num[row][col]=rand()%100;
		cout<<"\n\n\tB\t\tI\t\tN\t\tG\t\tO"<<endl;
		cout<<"\n\n";
			for(row=0;row<5;row++)
			{
				for(col=0;col<5;col++)
					{
					if(col==0)
						{
							num[row][col]=rand()%15;

								if(row==0)
									a=num[row][col];
								else if(row==1)
									b=num[row][col];
								else if(row==2)
									c=num[row][col];
								else if(row==3)
									d=num[row][col];
								else if(row==4)
									e=num[row][col];
						}
							
					else if(col==1)
					{ 
						num[row][col]=rand()%30;
					     
                                                   do{

 							if(num[row][col]<=15)
							{
								num[row][col]=num[row][col]+30;
							}
							else if(num[row][col]>=31)
							{
								num[row][col]=num[row][col]-1;
							}
						}while((num[row][col]<=15)&&(num[row][col]>=31));

						}
						else if(col==2)
						{ num[row][col]=rand()%15;
						do{
							if(num[row][col]<=30)
							{
								num[row][col]=num[row][col]+45;
							}
							else if(num[row][col]>=46)
							{
								num[row][col]=num[row][col]-1;
							}
						}while((num[row][col]<=30)&&(num[row][col]>=46));

						}
		

						else if(col==3)
						{ num[row][col]=rand()%15;
							do{
							if(num[row][col]<=45)
							{
								num[row][col]=num[row][col]+60;
							}
							else if(num[row][col]>=61)
							{
								num[row][col]=num[row][col]-1;
							}
						}while((num[row][col]<=45)&&(num[row][col]>=61));
						}
						else if(col==4)
						{ num[row][col]=rand()%15;
							do{
							if(num[row][col]<=60)
							{
								num[row][col]=num[row][col]+60;
							}
							else if(num[row][col]>=91)
							{
								num[row][col]=num[row][col]-1;
							}
						}while((num[row][col]<=60)&&(num[row][col]>=76));
						}

					if((row==2)&&(col==2))
							cout<<"\tFREE\t";
						else
							cout<<"\t"<<num[row][col]<<"\t";
					}
					cout<<"\n";
			}

			
			{
				cout<<"\n\n\tIs this the card you want to use? [0 for no only.] : ";
				cin>>ask;
			}
	}
			while(ask!=0);

}
Last edited on
@passionateswimr

I compressed the filling of the bingo card columns. If you need help understanding any section of this code, please ask, and I'll explain it as well as I can.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// BINGO.cpp : main project file.

#include<iostream>
#include<ctime>
#include <windows.h> 
//#include<conio.h> // Not needed here

using namespace std;

void ClearScreen();

int main()
{

	int num[5][5],number,row,col;
	int ask;
	bool ok = true;

	srand((unsigned) time(0)); // Better srand() call

	do{

		 ClearScreen(); // Using system calls, isn't advised. Here's a good ClearScreen() function
		cout<<"\n\n\t\t\t\t    BINGO GAME"<<endl;
		for(row=0;row<5;row++)
			for(col=0;col<5;col++)
				num[row][col]=0; // Zeroes out all the rows & columns
		cout<<"\n\n\tB\t\tI\t\tN\t\tG\t\tO"<<endl;
		cout<<"\n\n";
		for(col = 0;col < 5; col++)
		{
			for (row=0;row < 5; row++)
			{
				do
				{
					ok = true;
					number = 1+(col*15) + rand()%15;
					for (int ck=0;ck<5;ck++)
					{
						if (number == num[ck][col])
								ok = false; // Same number found, so create a new number
					}
				}while (!ok);
			num[row][col] = number;
			}
		}

		for(row = 0;row < 5; row++)
		{
			for (col=0;col < 5; col++)
			{
				if((row==2)&&(col==2))
					cout<<"\tFREE\t";
				else
				cout << "\t" << num[row][col] << "\t";

			}
			cout << endl;
		}

		{
			cout<<"\n\n\tIs this the card you want to use? [0 for no only.] : ";
			cin>>ask;
		}
	} while(ask==0);

	return 0;
}

void ClearScreen()
  {
   DWORD n;
  DWORD size;
  COORD coord = {0};
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
  GetConsoleScreenBufferInfo ( h, &csbi );
  size = csbi.dwSize.X * csbi.dwSize.Y;
  FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
  GetConsoleScreenBufferInfo ( h, &csbi );
  FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );
  SetConsoleCursorPosition ( h, coord );
  }
Topic archived. No new replies allowed.