Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Bingo Game I need help writing code that would declare a winner in a game of bingo, for example winning horizontally, vertically and accross.

C++ Bingo Game

I need help writing code that would declare a winner in a game of bingo, for example winning horizontally, vertically and accross. Right now the program ouputs and fills in the cards, but I am completelty lost on how to declare a winner if someone coud help me out I would really appreciare it. Here is what i have so far (I know that right now the cards are not displaying correctly but Im going to fix that.)

#include #include #include #include

//int callNumber(); 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; }

void 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 << " "; }

}

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; for (int x = 0; x < 5; x++) { 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; callNumber(); cout << "-----------------------------------------------------" << " "; } cin.get(); return 0; }

// The Game of Bingo

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

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions