Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that plays the game of \"guess the number”. The program shou

ID: 673662 • Letter: W

Question

Write a C++ program that plays the game of "guess the number”. The program should continue playing as long as the user did not guess the correct number.

First, declare theNumber as an integer whose value is 60.  Note: outside the loop.

Second, the program should then display the following (note :inside the loop):

I have a number between 1 and 100

Can you guess my number?

Please type your guess.

Then the player types a guess which will be stored in the variable userGuess. The program will then call the check function

bool check (int theNumber, int userGuess);

The check function should display one of the following:

Option 1: Excellent! You guessed the number!

Option 2: Too Low. Try Again.

Option 3: Too High. Try Again.

The check function will ALSO return true if the user guessed the number and will return false otherwise.

Your program should continue looping as long as the player guess is not correct (which is as long as the check function is returning false).

Test your program at least once for each of the options.

Explanation / Answer

#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
bool goOn=true;
while(goOn)
{
srand(time(0));
int number=rand()%100+1;;
int guess;
char answer;
cout<<"think of a number between 1-100. Take a guess: ";
cin>>guess;
while(guess!=number)
{
if(guess>number)
{
cout<<"Too high,Guess again: ";
cin>>guess;
}
if(guess<number)
{
cout<<"Too low,Guess again: ";
cin>>guess;
}
}
if(guess==number)
{
cout<<"Congrats!! You got it.";
}
cout<<"would you like to play Again? Enter y or n: ";
cin>>answer;
if(answer!='y')
{
goOn=false;
cout<<"thanks for playing you Rock!"<<endl;
}
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote