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

Design a guessing game program. The program will ask for a number between 0-101

ID: 3626828 • Letter: D

Question

Design a guessing game program. The program will ask for a number between 0-101 from user one. The program will then let user two attempt to guess the number in five turns or less.

a. The computer will notify user two if the number he/she is trying to guess is either:
i. Higher
ii. Lower
iii. The correct number

b. If user two guesses the correct number in five guesses or less, the computer will congratulate user two. If the number is not guessed in five guesses or less, the computer will congratulate user one.

c. All prompts and output should be neat and organized.

Explanation / Answer

Code:

#include<iostream>

#include<conio.h>

using namespace std;

int main()

{

    int rndnumber,uvalue,count=0,userwon=0,flag=0;

    srand(time(NULL));

    while(count<5)

    {

        cout<<"Enter your Guess Number : ";

        cin>>uvalue;

        rndnumber=rand()%100+1;

        if(rndnumber==uvalue)

        {

            cout<<"Your guess is Correct"<<endl<<endl;           

            userwon++;

        }

        else if(rndnumber >uvalue)        

              cout<<"Your guess is Lower, Random Number is "<<rndnumber<<endl<<endl;

        else

             cout<<"Your guess is Higher, Random Number is "<<rndnumber<<endl<<endl;

        if(userwon==2)

        {

            flag=1;

        }      

        count++;

        if(count-userwon>2)break;

     }

     if(flag==0)

         cout<<"Computer wins the game!"<<endl;

     else

         cout<<"User wins the game!"<<endl;

    getch();

    return 0;

}

Output:

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