Answer to Question #270780 in C++ for DANISH

Question #270780

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.


1
Expert's answer
2021-11-25T00:54:04-0500
//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;
    }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS