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

modify the numbers guessing game program. suppose that the variable num and gues

ID: 3550808 • Letter: M

Question

modify the numbers guessing game program. suppose that the variable num and guess are as declared and the diff is an int variables. Let diff= the absolute value of (num-guess). If diff is 0, then guess is correct and the program outputs a message indicating that the user guessed the correct number. Suppose diff is not 0. Then the program outputs the message as follows:

a: If diff is greater than or equal to 50, the program outputs the message indicating that the guess is very high(if guess is greater than num) or very low ( if guess is less than num).


b: If diff is greater than or equal to 30 and less than 50, the program outputs the message indicating that the guess is high (if guess is greater than num). or low ( if guess is less than num).


c: If diff is greater than 0 and less than 15, the program outputs the message indicating that the quess is somewhat high (if guess is greater than num) or somewhat low (if guess is less than num).


giver user no more than five tries to guess the number. (To find the value of num-guess,use the expressionabs (num-guess). header file cstdlib

Explanation / Answer

#include<iostream>

#include<cstdio>

#include<cmath>

using namespace std;


int main()

{

int num,guess,diff,f=0;

num=rand()%60;


for(int i=0;i<5;i++)

{

cout<<"Enter guess"<<endl;



cin>>guess;

if(num>guess)

{

diff=num-guess;

f=1;

}

else

diff=guess-num;

if(diff==0)

{

cout<<"user guessed correct number"<<endl;

break;

}

else if(diff>50)

{

if(f==1)

{

cout<<"guess is very low"<<endl;

}

else

cout<<"guess is very high"<<endl;

}

else if(diff>30)

{

if(f==1)

{

cout<<"guess is low"<<endl;

}

else

cout<<"guess is high"<<endl;

}

else

{

if(f==1)

{

cout<<"guess is somewhat low"<<endl;

}

else

cout<<"guess is somewhat high"<<endl;

}

}

return 0;

}