Question

Starting Out with C++ From Control Structures through Objects, Tony Gaddis, 9th edition, ISBN 978- 0134498379....

Starting Out with C++ From Control Structures through Objects, Tony Gaddis, 9th edition, ISBN 978- 0134498379.

Number guessing game Seed the random numbers. Have the computer randomly select a number between 1 and 10. Loop: Ask the user for a number between 1 and 10. Validate the user's entry. If invalid, repeat the loop. Compare the user's guess to the computer's and show the results: too low, too high, or matching

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int getRandom(){
   srand(time(0)); //seed random number generator
   int num = rand() % 10 + 1; // random number between 1 and 10
   return num;
}
int main()
{
   int num, guess,count=0;
   num=getRandom();
   cout << "Guess My Number Game\n\n";
  
   do
   {
   do{
   cout << "Enter a number betwee 1-10: ";
       cin >> guess;
   }while(guess<1 || guess>10);
       if (guess>num)
           cout << "Too large! Please try again.\n\n";
       else if (num<guess)
           cout << "Too small! Please try again.\n\n";
       else{
           cout << "\nCongratulations. You guessed it.\n";
           break;
       }
   } while (guess != num);

   return 0;
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Starting Out with C++ From Control Structures through Objects, Tony Gaddis, 9th edition, ISBN 978- 0134498379....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT