Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Bingo Game I need help with this program, I cant figure out how to get the game card to reset once the game is

C++ Bingo Game

I need help with this program, I cant figure out how to get the game card to reset once the game is over, currently it just displays the same card with the numbers marked out.

It should display a new card once the user wants to play again. Thanks

#include  #include  #include  #include  using namespace std; void FillCard(int iBCard[][5]); void DisplayCard(int iBCard[][5]); void DisplayCard(char cDCard[][5], int iBCard[][5]); //overloaded function int GetRandomNumber(bool reset); bool MarkCard(int iCard[][5], char cCard[][5], int iRanNum); bool CheckForXBingo(char cCard[][5]); void newCard(bool card); void WriteHeader(); int main() { /* * integer array used to hold drawn random * number values to prevent repeat numbers */ int iBingoCard[5][5]; char cDisplayCard[5][5]; bool bDidIWin = false, eCard = false; string sPlayAgain; int iRandomNum; WriteHeader(); bool firstNumberCalled; do { firstNumberCalled = true; bDidIWin = false; FillCard(iBingoCard); //populate cDisplayCard char array with spaces /* for(int row = 0; row < 5; row++) for(int col = 0; col < 5; col++) cDisplayCard[row][col] = ' ';*/ int count = 0; do { //display the card DisplayCard(cDisplayCard,iBingoCard); cout << " Hit the enter key for the next number called! "; char enter; cin.get(enter); //The head guy calls out the Bingo number! //We use the Get function if(firstNumberCalled == true) { iRandomNum = GetRandomNumber(true); firstNumberCalled = false; } else iRandomNum = GetRandomNumber(false); ++count; cout << " Count = " << count; cout << " The BINGO number is " << iRandomNum << endl; //place an asterisk on the blank card where a bingo match is made //MarkCard(iBingoCard, cDisplayCard, iRandomNum); //check for any 5 asterisks in a row bDidIWin = MarkCard(iBingoCard, cDisplayCard, iRandomNum); //send congratulatory message to user when they win if(bDidIWin == true) { cout << "Congratulations!! You won!!!" << endl; //Display the card again DisplayCard(cDisplayCard,iBingoCard); } }while(bDidIWin == false); cout << " Do you wish to run the program again? yes/no? "; getline(cin, sPlayAgain); }while(sPlayAgain == "yes"); newCard(eCard); cout << " Hope you had fun playing Bingo! "; /* Scaffolding code for testing purposes */ cin.ignore(256, ' '); cout << "Press ENTER to continue..." << endl; cin.get(); /* End Scaffolding */ return 0; } void DisplayCard(char cCard[][5], int iCard[][5]) { // cout << " Here is your BINGO card. Good Luck! "; char Top[10] = "BINGO"; int row, col, i; for(i = 0; i < 5; ++i) cout << setw(6) << Top[i]; cout << endl; cout << setw(6) << " -------------------------" << endl; //now print the card, row by row for(row = 0; row < 5; ++ row) { for(col = 0; col < 5; ++ col) { if(col == 2 && row == 2) cout << setw(6) << "FREE"; else { if(cCard[row][col] == '*') cout << setw(6) << cCard[row][col]; else cout << setw(6) << iCard[row][col]; } } cout << endl; } } int GetRandomNumber(bool reset) { static bool picked[76]; //we'll used values [1] thru [75] to keep //track of what's been called static int totalPicked = 0; //we'll keep count too, so we don't get //stuck in an infinite loop if(reset == true) //reset bools to start sending new values { for(int i = 0; i < 75; ++i) picked[i] = false; } int pick; bool stopLoop = false; do { pick = rand() % 75 + 1; if(picked[pick] == false) //not been used { totalPicked++; picked[pick] = true; stopLoop = true; if(totalPicked == 75) stopLoop = true; } }while(stopLoop == false); return pick; } bool MarkCard(int iCard[][5], char cCard[][5], int iRanNum) { for(int i = 0; i < 5; i++) for(int j = 0; j < 5; j++) if(iCard[i][j] == iRanNum) cCard[i][j] = '*'; bool bBingo = false; string s; int iCountDiag1 = 0, iCountDiag2 = 0, iCountVertical1 = 0, iCountVertical2 = 0, iCountVertical3 = 0, iCountVertical4 = 0, iCountVertical5 = 0, iCountHorizontal1 = 0, iCountHorizontal2 = 0, iCountHorizontal3 = 0, iCountHorizontal4 = 0, iCountHorizontal5 = 0; //set the center space to an asterisk for win logic cCard[2][2] = '*'; for(int i = 0; i < 5; i++) { //count the *'s along the (\) DIAGONAL line if(cCard[i][i] == '*') iCountDiag1++; //check for a winner via (/) DIAGONAL line if(cCard[i][4-i] == '*') iCountDiag2++; if(cCard[i][0] == '*') iCountVertical1++; if(cCard[i][1] == '*') iCountVertical2++; if(cCard[i][2] == '*') iCountVertical3++; if(cCard[i][3] == '*') iCountVertical4++; if(cCard[i][4] == '*') iCountVertical5++; } if( iCountDiag1 == 5 || iCountDiag2 == 5 || iCountVertical1 == 5 || iCountVertical2 == 5 || iCountVertical3 == 5 || iCountVertical4 == 5 ||iCountVertical5 == 5 || iCountHorizontal1 == 5 || iCountHorizontal2 == 5 || iCountHorizontal3 == 5 || iCountHorizontal4 == 5 || iCountHorizontal5 == 5) bBingo = true; return bBingo; } bool CheckForXBingo(char cCard[][5]) { bool bBingo = false; string s; int iCountDiag1 = 0, iCountDiag2 = 0, iCountVertical1 = 0, iCountVertical2 = 0, iCountVertical3 = 0, iCountVertical4 = 0, iCountVertical5 = 0; //set the center space to an asterisk for win logic cCard[2][2] = '*'; for(int i = 0; i < 5; i++) { //count the *'s along the (\) DIAGONAL line if(cCard[i][i] == '*') iCountDiag1++; //check for a winner via (/) DIAGONAL line if(cCard[i][4-i] == '*') iCountDiag2++; if(cCard[i][0] == '*') iCountVertical1++; if(cCard[i][1] == '*') iCountVertical2++; if(cCard[i][2] == '*') iCountVertical3++; if(cCard[i][3] == '*') iCountVertical4++; if(cCard[i][4] == '*') iCountVertical5++; } if( iCountDiag1 == 5 || iCountDiag2 == 5) bBingo = true; return bBingo; } void FillCard(int BCard[][5]) { int row, col, value, i, number; bool check[76]; //need values 1-75 //First fill check array with falses for(i = 0; i < 76; ++i) check[i] = false; bool newnumber; //flag to get another value bool found; for(col = 0; col < 5; ++ col) //work on each col { //now go down each row for(row = 0; row < 5; ++ row) { //check if we're at [2][2] FREE if(row == 2 && col == 2) { BCard[row][col] = 100; //indicate FREE } else { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { newnumber = false; while (!newnumber) { found = false; number = (rand() % 15) + (i * 15) + 1; for (int k = 0; k < 5; k++) { //compares row k and column i if (BCard[k][i] == number) found = true; } if (!found) { //compares row j and column i BCard[j][i] = number; newnumber = true; } } } } } } } } void newCard(bool card) { string nCard; cout << "Would you like to play agian? " ; cin >> nCard; if (nCard == "yes" || nCard == "y") { card == true; } else if (nCard == "no" || nCard == "n") { card == false; } } void WriteHeader() { //Opening greeting cout << "Welcome to the \"Bingo Game\" program!" << endl; cout << " The object of this program is to play bingo!" << endl; cout << "Keep tapping the enter key until you win!" << endl; cout << " NOTE: we check for BINGOs on --- | / and \\ "; } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

Commen Name with scientific name Tiger - Wolf- Lion- Cat- Dog-

Answered: 1 week ago