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
  • Starting out with C++ From Control Structures through Objects 8th Edition Chapter 7 Programming Challenges Number...

    Starting out with C++ From Control Structures through Objects 8th Edition Chapter 7 Programming Challenges Number 5

  • In c# create a program that generates a random number from 1 to 1000. Then, ask...

    In c# create a program that generates a random number from 1 to 1000. Then, ask the user to guess the random number. If the user's guess is too high, then the program should print "Too High, Try again". If the user's guess is too low, then the program should print "Too low, Try again". Use a loop to allow the user to keep entering guesses until they guess the random number correctly. Once they figure it, congratulate the user....

  • Will someone please post the solution to Starting out with C++ from control structures through objects...

    Will someone please post the solution to Starting out with C++ from control structures through objects 8th edition chapter 7 programming challenge # 16.

  • Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually...

    Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually kind of confusing to me. I keep getting lost in all of the words even though these are supposed to instruct me as to how to do this. Can I please get some help as to where to start? Word guessing game: Overview: Create a game in which the user has a set number of tries to correctly guess a word. I highly recommend...

  • Number 16. Chapter 3 Problem Comes from "Starting out with >>> C++ From Control Structures through...

    Number 16. Chapter 3 Problem Comes from "Starting out with >>> C++ From Control Structures through Objects" Ninth Edition. Checking work Programming Challenges 147 16. Senior Citizen Property Tax Madison County provides a $5,000 homeowner exemption for its senior citizens. For example, if a senior's house is valued at $158,000, its assessed value would be $94,800, as explained above. However, he would only pay tax on $89,800. At last year's tax rate of $2.64 for cach $100 of assessed value,...

  • Java How to Program, Early Objects ISBN-13: 9780133813432 Project Name: C2800_Proj1_RaceGame Source File Name: (Submit zip...

    Java How to Program, Early Objects ISBN-13: 9780133813432 Project Name: C2800_Proj1_RaceGame Source File Name: (Submit zip of these) RaceGame.java (contains main) RaceCar.java                                                                                                                                                              RaceGame is a text based car racing game. The user is car #1 and the computer is car #2. A car is drawn using 2 lines. The number on the first line is 1 for the user and 2 for the computer. __/1\__ -O---O- When the car has moved down the track, print underscore’s on the second line...

  • import java.util.Arrays; import java.util.Random; import java.util.Scanner; /** * TODO Write a summary of the role of...

    import java.util.Arrays; import java.util.Random; import java.util.Scanner; /** * TODO Write a summary of the role of this class in the * MasterMind program. * * @author TODO add your name here */ public class MasterMind { /** * Prompts the user for a value by displaying prompt. * Note: This method should not add a new line to the output of prompt. * * After prompting the user, the method will consume an entire * line of input while reading...

  • PROJECT TASKS 1. Read the problem definition below and write a C++ program that implements your...

    PROJECT TASKS 1. Read the problem definition below and write a C++ program that implements your solution. Readability of the program will be graded based on variable naming, indentation, commenting (not too little and not too much), spacing, consistency, and styling in general including choice of functions. [NOTE: the code at the end of this document does not completely meet requirements as it uses many single letter variables and has no internal documentation. You need to improve it.] 2. Compile...

  • NOTE if the player enters an invalid choice, the computer wins by default. NOTE To generate...

    NOTE if the player enters an invalid choice, the computer wins by default. NOTE To generate a random choice, this code uses the Random object as we have used in the previous labs. A value of 0 will be Plant, 1 will be Water and 2 will be Fire. Note that you MUST use these assignments of numbers to types for your submission to be able to pass the test cases! NOTE You MUST only declare and instantiate one single...

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