Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions