Question: void play ( Player &player 1 , Player &player 2 ) { int answer = rand ( ) % 1 0 0 ; bool win

void play(Player &player1, Player &player2)
{
int answer = rand()%100;
bool win = false;
while (!win)
{
win = checkForWin(player1, answer);
if (win)
{
player1.endRound(true);
player2.endRound(false);
return;
}
win = checkForWin(player2, answer);
if (win)
{
player1.endRound(false);
player2.endRound(true);
}
}
}
bool checkForWin(Player &player, int answer)
{
bool win = false;
cout << player.getName()<<"'s turn to guess." << endl;
int guess = player.getGuess();
cout<< "You guessed "<< guess <<".";
if (answer == guess)
{
cout << "You're right! You win!" << endl;
win = true;
}
else
player.wrongGuess(guess, answer);
return win;
}
Notice how we have Player objects used in these functions! This is the first class.

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!