Question: C++ Guessing Number Program The problem is to guess what number a computer has in mind. You will write a program that randomly generates an

C++ Guessing Number Program

The problem is to guess what number a computer has in mind. You will write a program that

randomly generates an integer between 0 and 100 , inclusive. The program prompts the user

to enter a number continuously until the number matches the randomly generated number. For

each user input, the program tells the user whether the input is too low or too high, so the user

can make the next guess intelligently. At the end of the game, display the total number of guesses and ask the user whether he/she would like to repeat the game. This program also requires input validation for the range and isdigit in case user inputs something that is not an integer.

Here is a sample run: Guess a magic number between 0 and 100

Enter your guess: 50 (Enter) Your guess is too high Enter your guess: 25 (Enter) Your guess is too low Enter your guess: 39 (Enter) Congratulations! You have guessed it right You have taken 3 guess(es) Would you like to play again?(Y/N)

What I have so far:

#include #include #include #include #include

using namespace std;

int main{

int guess, number, count;

char answer;

srand((number)time(0));

bool invalid = true;

bool end = true;

bool validation =true

while(end){

while(invalid){

bool validation = true;

count = 0;

cout<<"Please enter a number between 1-100: "<

cin>>guess;

for(int i = 0; i < guess.size(); i+++){

if(isdigit(guess[i]) != true){

validation = false;

count++;

continue;

}

}

cout<<"Please enter a real number."<

if(validation = false){

count++;

}

stringstream x(guess);

x >> number;

if(number > 100){

cout <<"out of the range."<

count++;

}

if(num < 0){

cout<<"out of the range."<

count++;

}

if(check == guess.size() && number > 0 && number <101){

invalid = false;

}

}

} if(guess > number){

cout<< "Guess is too big!"<

count++;

cout<

if(guess < number){

cout<< "Guess is too low!"<

count++;

cout<

else

cout<< "Congratulation! You got the number."<

cout<

}

}

cout>>("Do you want to play again? (Y/N))">>endl;

cin>>char;

if((char == 'y') || (char == 'Y')){

return 0

}

else if((char == 'n') || (char == 'N')){

break;

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!