Question: i nned help fixing this code so that each prize is printed randomly 3 times so that there are 15 squares with prizes and 10

i nned help fixing this code so that each prize is printed randomly 3 times so that there are 15 squares with prizes and 10 empty

code:

#include #include #include #include

using namespace std;

int randRange(int low, int high){ return rand() % (high - low + 1) + low; }

void populateBoard(string arrBoard[5][5], string prizes[5]) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { arrBoard[i][j] = " "; } }

srand(time(0)); for (int i = 0; i < 9; i++) { int count = 0; while (count < 3) { int x = randRange(0, 4); int y = randRange(0, 4); for (int i = 0; i < 15; i++){ if (arrBoard[x][y] == " ") { arrBoard[x][y] = prizes[i]; count++; } } } } }

string playGame(string arrBoard[5][5], int pennies, string prizes[5]) { int prizeCounts[5] = {0}; string winner = "NONE"; while (pennies > 0) { int x = randRange(0, 4); int y = randRange(0, 4); if (arrBoard[x][y] != " ") { int prizeIndex = -1; for (int i = 0; i < 9; i++) { if (arrBoard[x][y] == prizes[i]) { prizeIndex = i; break; } } prizeCounts[prizeIndex]++; if (prizeCounts[prizeIndex] == 3) { winner = prizes[prizeIndex]; break; } pennies--; } } return winner; }

int main() { string arrBoard[5][5]; string prizes[5] = {"PUZZLE", "GAME", "DOLL", "BALL", "POSTER"};

populateBoard(arrBoard, prizes);

for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { cout << arrBoard[i][j] << "\t"; } cout << endl; } int pennies = 10; string winner = playGame(arrBoard, pennies, prizes); cout << "Prize won: " << winner << endl; 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!