Explore BrainMass
Share

# High-Low game in C++

This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

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

Hi-Lo Game

This 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 <iostream>

#include <iomanip>

using namespace std;

char chr;

int main()

{

int number;

int guess;

int tries;

char name;

cin>>name;

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

cout<<"Welcome to the Hi-Lo Game,"<<name<<"!"<<endl;

cout<<"********************************"<<endl;

srand(number>0);

do

{

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

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

cin>>guess;

if (number>guess)

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

tries++;

} while (number<guess);

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>>chr;

return 0;

}.