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

For program 2 you will write a simple number guessing game. The game will genera

ID: 3884343 • Letter: F

Question

For program 2 you will write a simple number guessing game. The game will generate a random number in the range of 0 -99. It will prompt the player to enter a guess and then tell the player if his/her guess was high or low. The program will loop, prompting and reading input and providing feedback to the player. This operation allows the player to "zero in" and ultimately guess the game's target number. A. Create a number guessing game in a source code file guess.cpp B. You may not use any functions from the stdio library C. The rest of the requirements are expressed in the pseudo code that also describes the game's behavior. seed the random number generator (details given below) generate a target number between 0 and 99 (details given below) loop (e.g., while (true)) - statements a-g are in the loop body a. prompt the user to guess a number from 0 to 99 (0 and 99 are allowed) b. read the guess c. if the guess is equal to -1 or less than 0 (your choice), terminate the program (this is a way to end the program early) d. if the guess and the target number are equal, print a success message (e.g., "Right" or "You Win" or similar) and terminate the program e. if the guess is less than the target number, print "Low" or a similar message f. if the guess is greater than the target number, print "High" or a similar message g. continue with next iteration of the loop (go back to step 3.a - end the loop body)

Explanation / Answer

#include <iostream>
#include <cstdlib>

using namespace std;

int main() //main function
{
int n; //variable declaration
n=0;
double rnd;
cout<<"******Welcome to the Guessing Number Game******"<<endl;
cout<<"A number is already generated you have to guess the number"<<endl;
rnd = rand() % 101; //random number generated
cout<<"Enter your Guess : ";
cin>>n; //asking user for the guess
do
{
cout<<"Enter your Guess : ";
cin>>n;
if(n == -1 || n < 0) //checking if less than 0 it will exit
exit(0);
if(n>rnd) //checking if number greater than the random number
cout<<"Your Guess is greter than the number"<<endl;
if(n<rnd) //checking if number lesser than the random number
cout<<"Your Guess is lesser than the number"<<endl;
if(n==rnd) //if match found
{
cout<<"You have guessed the correct number "<<rnd;
exit(0);
}
}while(n!=rnd);
cout<<"You have guessed the correct number "<<rnd;

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