Purchase Solution

High-Low game in C++

Not what you're looking for?

Ask Custom Question

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

char name;

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

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

} while (answer=='Yes');

cin>>chr;

return 0;

}.

Purchase this Solution

Solution Summary

The solution assists with writing a high-low game in C++.

Purchase this Solution


Free BrainMass Quizzes
Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.