Question: Bingo Game in C++ Hello I have this program that plays a game of bingo but need help writting three equations that will check for

Bingo Game in C++

Hello I have this program that plays a game of bingo but need help writting three equations that will check for winner in three different ways, one for horizontal, vertical and across, the current one just check in one way (if you could explain how the equations work I would appreciate it) Also need help with fixing the output of the cards. Thanks!!

#include #include #include #include

using namespace std;

void displayCard() { int bingoCard[5][5]; int i, j, k, number; bool found = false; bool newnumber = false;

cout << setw(2) << " B " << " I " << " N " << " G " << " O " << endl;

//start generating numbers for the bingo cards for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { newnumber = false; while (!newnumber) { found = false; number = (rand() % 15) + (i * 15) + 1; for (k = 0; k < 5; k++) { //compares row k and column i if (bingoCard[k][i] == number) found = true; } if (!found) { //compares row j and column i bingoCard[j][i] = number; newnumber = true; } }

}

} for (int i = 0; i < 5; i++) { //creates the free space for the cards for (int j = 0; j < 5; j++) { if (bingoCard[i][j] == bingoCard[2][2]) cout << setw(3) << right << " X "; else cout << setw(2) << bingoCard[i][j] << " "; } cout << endl; } cout << endl;

}

int callNumber() { int num = rand() % 75 + 1; if (num <= 15) { cout << "B " << num << " "; } else if (15 < num && num <= 30) { cout << "I " << num << " "; } else if (30 < num && num <= 45) { cout << "N " << num << " "; } else if (45 < num && num <= 60) { cout << "G " << num << " "; } else if (60 < num && num <= 75) { cout << "O " << num << " "; } return num;

}

int main()

{ //local variables for int players = 0; int player = 0; srand(static_cast(time(NULL))); //call a random function that generates a random number

// ask user how many cards will be handed out cout << "How many players are playing BINGO? "; cin >> players;

//get 5 unique digits to play game for each player

int **input = (int **)malloc(players * sizeof(int *)); for (int i = 0; i

for (int x = 0; x < 5; x++) { cout << "Round # " << x + 1 << endl; int savePlayer = players; while (players > 0) { player++; cout << "Player " << player << ":" << endl; displayCard();

//loops back up till player = 0 players = players - 1; } players = savePlayer; player = 0;

while (players > 0) { cout << "Player " << player +1 << ":" << endl; input[player][x] = callNumber(); player++;

//loops back up till player = 0 players = players - 1;

} players = savePlayer; player = 0; }

//checck for bingo winner for (int i = 0; i < players; i++) { int sum = 0; for (int j = 0; j < 5; j++) { sum += input[i][j]; } if (sum > 30 && sum <= 45) cout << "player " << i+1 << "is BINGO Winner!" << endl; else cout << "player " << i << " is Not Winner" << endl; }

cout << "-----------------------------------------------------" << " ";

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!