Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HiLo Guessing Game The program is in C++. This assignment utilizes: - random numbers - loops - conditional statements - basic input/output Write a program

HiLo Guessing Game

The program is in C++.

This assignment utilizes:

- random numbers

- loops

- conditional statements

- basic input/output

Write a program to play the Hi-Lo guessing game! In particular, your program should:

Generate a random number from 1 to 100.

Ask the user to guess the number

If the user is right, the game ends

If the user's guess is too high or too low, the program informs the user of that fact and asks for another guess.

This repeats until the user gets the number correct.

Further, your program should keep track of how many guesses the user takes to get the number right. An appropriate insult/compliment should then be issued to the user. For example:

11 or more "What a terrible score!..."

9-10 "Not too shabby, but not too good either...

7-8 "That's pretty good but you can do better..."

5-6 "That's a very good score..."

0-4 "Amazing! Or was it luck?"

Here is a sample run:

Lets play a Number Guessing Game!

Guess a number between 1 and 100

40

Too low!!

Guess a number between 1 and 100

90

Too high!!

Guess a number between 1 and 100

60

Too high!!

Guess a number between 1 and 100

50

Too low!!

Guess a number between 1 and 100

55

Too low!!

Guess a number between 1 and 100

56

You win!!

It took you 6 guesses.

That's a very good score...

Some Help (random numbers): To generate a random number from 1-10 in c++, do the following:

First, seed the random number generator. To do this, add #include to the top of your program, and add the following command:

srand(time(0));

Now use rand() to generate pseudo random numbers. Each call to rand() will generate a giant random number. Take the result and get the remainder of this giant number modulus 10 using rand() % 10. The remainder of any number when divided by 10 will be a number from 0 to 9. Take the result and add 1 to it to get a number from 1-10:

srand(time(0));

int x1 = rand() % 10 + 1; //will be something like 4

int x2 = rand() % 10 + 1; //will be something like 1

int x3 = rand() % 10 + 1; //will be something like 6

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

4. I can tell when team members dont mean what they say.

Answered: 1 week ago