Question: Help in C Language please, I have a program for the generation of bingo cards. Now that I have my program my question is how
Help in C Language please,
I have a program for the generation of bingo cards. Now that I have my program my question is how do I create a program to play bingo?
I will provide my program for bingo cards (My program):
CREATE A PROGRAM THAT WILL:
Add an option 4 to your menu for Play Bingo
read in a bingo call (e,g, B6, I17, G57, G65)
checks to see if the bingo call read in is valid (i.e., G65 is not valid)
marks all the boards that have the bingo call
checks to see if there is a winner, for our purposes winning means
5 tokens in a row or column
5 tokens in a diagonal
1 token in each of the 4 corners of the game board
Loop accepting bingo calls until there is a winner, and display an appropriate message specifying which user won, and how they won (5 in a row with calls B6, I20, ...; 5 in a column with calls ...; 5 on a diagonal with calls ... ; 4 corners with calls ...)
Below is the working code I have so far, just need help with what is asked above. (My program):
#include
#include
#include
int get_random_number(int min, int max) {
return min + (rand() % (max - min + 1)); //Gets input of random number from user
}
int min_for_col(int column_index) {
return (column_index * 15) + 1;
}
int max_for_col(int column_index) {
return (column_index + 1) * 15;
}
void print_bingo_card(int cards[5][10][5][5], int player, int card) { /*Begins to form construct of bingo card */
int i, j;
printf(" B I N G O ");
for(i = 0; i < 5; ++i) {
for(j = 0; j < 5; ++j) {
if(i == 2 && j == 2) {
printf(" ");
} else {
printf("%2d ", cards[player][card][i][j]);
}
}
printf(" ");
}
printf(" ");
}
int main() { //main defined
srand(time(NULL));
int num_players, num_cards, i, j, k, l, m, num;
int bingo_cards[5][10][5][5]; //Array for 4 dimensional selection of bingo cards
int count[75]; //Assigning count integer index to 1-75 as instructed
int num_rows = 5, num_cols = 5; //Declaring number of rows and columns for Bingo card game
int already_exists = 0;
printf("Please enter number of players: "); //Prompts user input for number of players for bingo card game
scanf("%d", &num_players);
printf("Please enter number of cards per player: ");//Prompts user input for number of cards per player
scanf("%d", &num_cards);
for(i = 0; i < num_players; ++i) { // num players incremented by 1 if user chooses to add players
for(j = 0; j < num_cards; ++j) {//num cards incremented by 1
for(k = 0; k < num_cols; ++k) {// num cols incremented by 1
for(l = 0; l < num_rows; ++l) { //num rows incremented by 1
while(1) {
num = get_random_number(min_for_col(k), max_for_col(k)); /* Gets random number for column and checks to see if already exist*/
already_exists = 0;
for(m = 0; m < l; ++m) {
if(bingo_cards[i][j][m][k] == num) {
already_exists = 1;
}
}
if(already_exists == 0) { //Test cases checking if user input exists in row/col
break;
}
}
bingo_cards[i][j][l][k] = num;
}
}
}
}
// calculation for histogram using for loop.
for(i = 0; i < 75; ++i) {
count[i] = 0;
}
for(i = 0; i < num_players; ++i) {
for(j = 0; j < num_cards; ++j) {
for(k = 0; k < num_rows; ++k) {
for(l = 0; l < num_cols; ++l) {
if(!(k == 2 && l == 2)) {
count[bingo_cards[i][j][k][l] - 1]++;
}
}
}
}
}
while(1) {
printf("1. To select user/bingo card to display "); //Prompts user input to display bingo card
printf("2. To show histogram "); //Prompts user inpu to display histogram
printf("3. Exit "); //If user no longer wishes to play user exits
printf("Please enter your choice: ");
scanf("%d", &i);
switch(i) {
case 1:
printf("Please enter player number(%d - %d): ", 1, num_players);
scanf("%d", &j); //Read in user input 1-75
printf("Please enter card number(%d - %d): ", 1, num_cards);
scanf("%d", &k); //Read in user input for card number 1-75
print_bingo_card(bingo_cards, j - 1, k - 1);
break;
case 2:
for(j = 0; j < 75; ++j) {
printf("%2d: ", j + 1);
for(k = 0; k < count[j]; ++k) {
printf("*");
}
printf(" ");
}
break;
case 3:
return 0;
default:
printf("Invalid choice. Please try again!!"); //test cases if user enters letter or number not listed bingo game exits
break;
}
}
return 0;
}
(Heres a sample Execution:)
Enter the number of players:5 Enter the number of BINGO cards per player:10 You are playing a game with 5 players and each player will have 10 cards We have generated 50 bingo cards. Please choose an option from the following menu: 1) Display a bingo card 2) run a histogram across all bingo cards generated 3) exit 4) Play Bingo! 1 You have chosen 1 Enter the player and players card you would like to display, First player is 0, last player is 4 First card is 0, last card is 9 2 2 B I N G O 8 17 44 51 67 6 27 43 54 68 10 24 free 52 62 2 26 39 47 65 12 16 33 59 63 Please choose an option from the following menu: 1) Display a bingo card 2) run a histogram across all bingo cards generated 3) exit 4) Play Bingo! 4 You have chosen 4 Enter the called value:I17 read in I 17marking I17 on the boards Enter the called value:I72 read in I 72, Invalid Bingo Call Enter the called value:I27 read in I 27marking I27 on the boards Enter the called value:I24 read in I 24marking I24 on the boards Enter the called value:I62 read in I 62, Invalid Bingo Call Enter the called value:I26 read in I 26marking I26 on the boards Enter the called value:I16 read in I 16marking I16 on the boards we have a winner in column 1 on player 2's card # 2 I17 I27 I24 I26 I16
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
