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

Write a program that generates a random number between 1 and 100 and asks the us

ID: 3695008 • Letter: W

Question

Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display "Too high. Try again." If the user’s guess is lower than the random number, the program should display "Too low. Try again." The program should use a loop that repeats until the user correctly guesses the random number. Then the program should display "Congratulations. You figured out my number."

You must use a do-while loop

Explanation / Answer

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
   int r,a;
   r=rand()%100+1;
   do
   {

       cout<<"Guess Number";
       cin>>a;
       if(a>r)
           cout<<"Too high. Try again";
       else if(a<r)
           cout<<"Too low. Try again";
       else
       {
           cout<<"Congratulations. You figured out my number.";
           break;
       }

   }while(1);
   getch();

}

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