Question: Attached is my program which generates bingo cards. I need a basic program in C to modify my program with the following instructions: Create a
Attached is my program which generates bingo cards. I need a basic program in C to modify my program with the following instructions:
Create a program in C 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( diagnols meaning upper right corner to lower left and vice versa)
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 ...)
-The program created should have multiple functions here, 1 function that checks for each way of winning (row, column, diagnal, 4 corners)
Here is a sample of how output should look like:

Here is my program which should include program needed:
#include
#include
int main()
{
int numPlayers = 0; // how many players
int cardsPerPlayer = 0;//cards the user inputs per player
int rows=5;
int col =5;
int i=0;
int j=0;
int k=0;
int num=15;
srand((int)time(0)); // generating the random seed to make unique cards
while (numPlayers>5 || numPlayers
{
printf("Please enter the number of players: "); //user to input the number of players
scanf("%d", &numPlayers);
if (numPlayers>5 || numPlayers
{
printf("A maximum of 5 players per game: ");
}
}
printf(" ");
while (cardsPerPlayer>10 || cardsPerPlayer
{
printf("How many cards would you like to generate per player? ");//user to input the number of cards per player
scanf("%d", &cardsPerPlayer);
if (cardsPerPlayer>10 || cardsPerPlayer
{
printf("A maximum of 10 cards per player ");
}
}
printf(" ");
int totalPlayerCards;
printf("You are playing a game with %d players and each player will have %d cards. ", numPlayers, cardsPerPlayer);
totalPlayerCards=numPlayers * cardsPerPlayer;
printf("We have generated %d bingo cards. ", totalPlayerCards);//This indicates total amount of cards generated
int bingoBoard[numPlayers][cardsPerPlayer][rows][col] ;//this is my 4 dimensional array
// generates the arrays
for(i=0; i
{
for(j=0; j
{
for(rows=0; rows
{
for(col=0; col
{
if(col==0) // generates the appropriate values for each column
{
bingoBoard[i][j][rows][col] = (rand()%15)+1;
}
if(col==1)
{
bingoBoard[i][j][rows][col] = (rand()%15)+16;
}
if(col==2)
{
bingoBoard[i][j][rows][col] = (rand()%15)+31;
}
if(col==3)
{
bingoBoard[i][j][rows][col] = (rand()%15)+46;
}
if(col==4)
{
bingoBoard[i][j][rows][col] = (rand()%15)+61;
}
}
}
}
}
for(i=0; i
{
for(j=0; j
{
for(rows=0; rows
{
for(col=0; col
{
for(k=1; k
{
while (bingoBoard[i][j][rows][col] == bingoBoard[i][j][rows-k][col]) //it checks the current spot in the array and compares it to the previous values of the column
{
bingoBoard[i][j][rows][col] = (rand()%15) + (15*col) +1; // if the numbers match then it assigns it a new value
}
}
}
}
}
}
//menu of options for the user to select from
printf("Please choose an option from the following menu: ");
printf("1) Display a bingo card ");
printf("2) run a histogram across all bingo cards generated ");
printf("3) exit ");
int menuOptions;
while (menuOptions>3|| menuOptions
{
scanf("%d", &menuOptions);
if (menuOptions>3|| menuOptions
{
printf("That option is not available. ");
printf("Choose between 1, 2, or 3 ");
}
}
printf(" ");
printf("You have chosen %d ", menuOptions);
do
{
if(menuOptions==1) // choice 1 prints a specific card
{
int player; // user picked player
int playerCard; // user defined card
int userPlayer=0;
int userCard=0;
printf("Enter the player and players card you would like to display: ");
scanf("%d %d", &player, &playerCard);
userPlayer = player - player;
userCard = playerCard - playerCard;
printf("First player is %d, and last player is %d ", userPlayer, (player-1));
printf("First card is %d, last card is %d ", userCard, (playerCard-1));
printf("You are viewing player %d's Bingo Card %d ", player, playerCard);
printf(" ");
printf("B\tI\tN\tG\tO ");
for(rows=0; rows
{
for(col=0; col
{
if(rows==2 && col==2)//this tells program to have a "free" spot in row 2, column 2
{
bingoBoard[numPlayers-1][cardsPerPlayer-1][rows][col] = -1; // sets the free spot to -1 as a flag. -1 does not get picked up by the histogram
printf("free\t");
col++; // moves to the next spot to continue on with the array
}
printf("%d\t",bingoBoard[player-1][playerCard-1][rows][col]);
}
printf(" ");
}
}
if (menuOptions==2) // choice 2 runs a histogram on all values generated
{
printf("HISTOGRAM ");
int l=0;
int seen [75] = {0}; // array that counts how many times a value has been seen
for(l=1; l
{
for(i=0 ; i
{
for(j=0 ; j
{
for(rows=0 ; rows
{
for(col=0; col
{
if(bingoBoard[i][j][rows][col]== l) // if any element in the array matches, l gets incremented
{
seen[l-1] = seen[l-1] +1;
}
}
}
}
}
printf("%d-%d\t", l, seen[l-1]); // prints out how many times each number has been seen
if (l==10)//if l equals 10, a new line will be generated
{
printf(" ");
}
if (l==20)//if l equals 20, a new line will be generated
{
printf(" ");
}
if (l==30)//if l equals 30, a new line will be generated
{
printf(" ");
}
if (l==40)//if l equals 40, a new line will be generated
{
printf(" ");
}
if (l==50)//if l equals 50, a new line will be generated
{
printf(" ");
}
if (l==60)//if l equals 60, a new line will be generated
{
printf(" ");
}
if (l==70)//if l equals 70, a new line will be generated
{
printf(" ");
}
}
}
printf(" ");
printf(" ");
//asks the user what they want to do next
printf("Please choose an option from the following menu: ");
printf("1) Display a bingo card ");
printf("2) run a histogram across all bingo cards generated ");
printf("3) exit ");
scanf("%d", &menuOptions);
printf("You have chosen %d ", menuOptions);
if (menuOptions>3|| menuOptions
{
printf("That option is not available. ");
printf("Choose between 1, 2, or 3 ");
}
} while(menuOptions != 3); // program quits if user enters 3
printf("Thank you for playing! ");
printf("Goodbye");
return 0;
}
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! You have chosen 1 Enter the player and players card you would like to display, First player is e, last player is 4 First card is e, last card is9 0 17 44 51 67 54 68 52 62 39 47 65 59 63 8 6 10 27 24 free 26 16 43 12 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: 117 read in I 17marking I17 on the boards Enter the called value: 172 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 124 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 117 127 124 126 I16 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! You have chosen 1 Enter the player and players card you would like to display, First player is e, last player is 4 First card is e, last card is9 0 17 44 51 67 54 68 52 62 39 47 65 59 63 8 6 10 27 24 free 26 16 43 12 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: 117 read in I 17marking I17 on the boards Enter the called value: 172 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 124 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 117 127 124 126 I16
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
