Create a code in hi-lo game


Discuss the below:

Q: Build a code in C++ that will play the high-lo game.

Hi-Lo Game

The game will ask the user to guess a number between 0 and 10. Suppose the game wants to guess the number 7. The game will keep helping the user to guess the number until the user enters 7. A sample output will look like the following:

Welcome to the Hi-Lo Game, Sadia!

Guess a number between 0 - 10 :
5
Your guess is too low. Guess again!
8
Your guess is too high. Guess again!
6
Your guess is too low. Guess again!
7
That is correct, you win!
Would you like to give the game another try? (Yes or No)
Yes
Guess a number between 0 - 10:
Your guess is too low. Guess again!
That is correct, you win!

#include

#include

using namespace std;

char chr;

int main()

{

int number;

int guess;

int tries;

char answer;

char name;

cout<<"What is your name?n";

cin>>name;

cout<<"********************************n";

cout<<"Welcome to the Hi-Lo Game,"<

cout<<"********************************"<

srand(number>0);

do

{

number=rand()%10+1; break;

cout<<"Enter a number between 0 and 10"<

cin>>guess;

if (number>guess)

cout<<"Your guess is too low. Guess again!n";

tries++;

} while (number

cout<<"Your guess is too high. Guess again!n";

tries=1;

if (number==guess)

cout<<"That is correct, you win!n";

do

{

cout<<"Would you like to give the game another try? (Yes or No)n";

cin>>answer;

} while (answer=='Yes');

cin>>chr;

return 0;

}.

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Create a code in hi-lo game
Reference No:- TGS01939276

Now Priced at $20 (50% Discount)

Recommended (94%)

Rated (4.6/5)