|

Question: “NONO * Problem2.cpp * The Class Number-game Implements A “”guess Your Number”” Game, By Repeatedly * Asking The User Questions About The Number They Are Thinking Of. Write A Main * Which Creates An Instance Of Number-game And Then Uses It To Play The Game With * The User. #include Using Namespace Std; 11 // You Shouldn’t Need To Modify The Number-game …”

NONO * Problem2.cpp * The Class Number-game Implements A “guess Your
Number” Game, By Repeatedly * Asking The User Questions About The Number
They Are Thinking Of. Write A Main * Which Creates An Instance Of
Number-game And Then Uses It To Play The Game With * The User. #include
Using Namespace Std; 11 // You Shouldn’t Need To Modify The Number-game …

Draw the major product formed in the following reaction

NONO * problem2.cpp * The class number-game implements a guess your number game, by repeatedly * asking the user questions

NONO * problem2.cpp * The class number-game implements a “guess your number” game, by repeatedly * asking the user questions about the number they are thinking of. Write a main * which creates an instance of number-game and then uses it to play the game with * the user. #include using namespace std; 11 // You shouldn’t need to modify the number-game class (although you can if you want). 12 class number-game { public: int low = 1, high = 100; bool done = false; /* begin() (Re)starts the number game. void begin() { low = 1; high = 100; done = false; cout

Expert Chegg Question Answer:

free chegg question answer

Smart Teacher

solution:

given data:

#include<iostream>
using namespace std;
class number_game{
public:
int low=1,high=100;
bool done=false;

void begin()
{
low=1;
high=100;
done=false;

cout<<“Think of a number between “<<low<<” and “<<high<<endl;
}

void ask()
{
if(finished())
{
cout<<“The game is over Sorry.\n”;
return;
}

int mid=(low+high)/2;

cout<<“Hmm..Is your number less than (l) , greater than (g), or equal to (e) “<<mid<<” ? “;
char answer;
cin>>answer;


if(answer==’e’)
{
cout<<“I win!\n”;
done=true;
}
else if(answer==’l’)
{
high=mid-1;
}
else if(answer==’g’)
{
low=mid+1;
}
else
{
cout<<“I dont understand.\n”;
}

if(low>high)
{
cout<<“Hey ,you are cheating!\n”;
done=true;
}
}

bool finished()
{
return done;
}
};
int main()
{
cout<<“Welcome to the number guessing game\n”;
//Create an instance of the object number_game
number_game game;
//Start the game
game.begin();
//As long as the game doesnt end keep asking the user about his guess
while(!game.finished())
{
game.ask();
}

return 0;
}

C:\Users\User\Desktop Chegg\Number Guessing Game numbers.exe Welcome to the number guessing game Think of a number between
C:\Users\User\Desktop Chegg\Number Guessing Game numbers.exe Welcome to the number guessing game Think of a number between
C:\Users\User\Desktop Chegg\Number Guessing Game numbers.exe Welcome to the number guessing game Think of a number between
numbers.cpp - Code::Blocks 13.12 Eile Edit View Search Project Build Debug Fortran woSmith Tools Tools+ Plugins DoxyBlocks Se

please give me thumb up

Free Chegg Question Answer

Leave a Reply

Your email address will not be published. Required fields are marked *