LOOPS ( READ QUESTION AND SOLVE IT AS REQUIRED)
If diff is 0, then guess is correct and the program outputs a message indicating that the user guessed the correct number.
1. 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).
2. 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).
3. If diff is greater than or equal to 15 and less than 30, the program outputs the message indicating that the guess is moderately high (if guess is greater than num) or moderately low (if guess is less than num).
4. If diff is greater than 0 and less than 15, the program outputs the message indicating that the guess is somewhat high (if guess is greater than num) or somewhat low (if guess is less than num).
Give the user no more than five tries to guess the number.
//Number guessing game.LOOPS
#include <iostream>
using namespace std;
int main()
{
int diff,n;
//Give the user no more than five tries to guess the number
for(int n=0; n<5; n++){
cout<<"Enter the value for the Guess: ";
cin>>diff;
if(diff==0)
{
cout<<"The user guessed the correct number"<<endl;
}
else if(diff>=50)
{
cout<<"The guess is very high"<<endl;
}
else if(diff>=30 && diff<50)
{
cout<<"The guess is high"<<endl;
}
else if(diff>=15 && diff<30)
{
cout<<"The guess is moderately high"<<endl;
}
else if(diff>0 && diff<15)
{
cout<<"The guess is somewhat high"<<endl;
}
}
}
Comments
Leave a comment