You are on page 1of 2

BINGO Card Generator Program

Chavez, Dy
21 April 2015

1
2
3
4
5
6

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio_ext.h>
#include <iomanip>
using namespace std;

7
8
9

void printHeader( char [] );


void printAsterisk( int );

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

int main() {
char sel, bingo[6] = {B, I, N, G, O, \0};
int bingo_num[5][5];
printHeader( bingo );
do {
cout << "\tMENU" << endl;
cout << "\t[G] - Generate BINGO card" << endl;
cout << "\t[D] - Display BINGO card" << endl;
cout << "\t[E] - Exit program" << endl;
do{
cout << endl << "\tSelection> ";
cin >> sel;
__fpurge( stdin ); // flush cin stream
if ( sel == G || sel == D || sel == E )
break;
else
cout << "\tInvalid Entry! Try again!" << endl;
}while( true );
cout << endl;
if ( sel == D ) {
if ( bingo_num[0][0] == 0 )
cout << "\tGenerate BINGO Card First!" << endl;
else {
cout << "\t+---+---+---+---+---+" << endl;
cout << "\t|-B-|-I-|-N-|-G-|-O-|" << endl;
cout << "\t+---+---+---+---+---+" << endl;
for ( int col = 0 ; col < 5 ; col++ )
{
cout << "\t|";
for ( int row = 0; row < 5 ; row++ )
cout << setfill( ) << setw( 3 ) << bingo_num[row][col] << "|";
cout << endl << "\t+---+---+---+---+---+" << endl;
}
cout << endl;
}
}
else if ( sel == G ) {
int num1;
bool samenum;
for ( int col = 0; col < 5 ; col++ ) {
for ( int row = 0; row < 5 ; row++ ) {
do {
samenum = false;
num1 = rand()% 15 + 1 + ( 15 * col );
1

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

for ( int check = 0; check < row; check++ ){


if ( num1 == bingo_num[check][col] )
samenum = true;
}
}while ( samenum );
bingo_num[col][row] = num1;
bingo_num[2][2] = 0;
}
}
cout << "\tSuccessfully generated!\nSelect [D] to display." << endl;
}
}while ( sel != E );
cout << "\tGood Bye!" << endl;
return 0;
}
void printHeader( char title[] ) {
cout << endl << \t;
printAsterisk( strlen( title ) + 4 );
cout << endl << "\t* " << title << " *" << endl << \t;
printAsterisk( strlen( title ) + 4 );
cout << endl;
return;
}
void printAsterisk( int x ) {
for ( int i = 0; i < x; i++ )
cout << "*";
return;
}

You might also like