Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ modify the program so the user is guessing a random number between 1-100 (instead of 1-10). For full credit (+/- 15pts) add logic that

C++

modify the program so the user is guessing a random number between 1-100 (instead of 1-10). For full credit (+/- 15pts) add logic that tells the user if their guess is hot (within 10). Here is a sample of the console:

Guess the number! I'm thinking of a number from 1 to 100 Your guess: 30 Too low. Your guess: 50 Too low, but you are getting warm! Your guess: 60 Too high, but you are getting warm! Your guess: 55 Too low, but you are getting warm! Your guess: 56 Too high, but you are getting warm! Bye!

#include #include #include

using namespace std;

int main() { int upper_limit = 10; cout << "Guess the number! "; cout << "I'm thinking of a number from 1 to " << upper_limit << " ";

// get a random number between 1 and the upper limit srand(time(nullptr)); // seed the rand() function int number = rand() % upper_limit; // number is >= 0 and < upper_limit ++number; // number is >= 1 and <= upper_limit

int count = 1; int guess = 0; while (guess != number) { cout << "Your guess: "; cin >> guess;

if (guess < 1 || guess > upper_limit) { cout << "Invalid guess. Try again. "; } else if (guess < number) { cout << "Too low. "; ++count; } else if (guess > number) { cout << "Too high. "; ++count; } else { cout << "You guessed it in " << count << " tries. "; } } cout << "Bye! "; }

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 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

What is moral hazard and how might it affect entrepreneurial firms?

Answered: 1 week ago

Question

Know how productivity improvements impact quality and value.

Answered: 1 week ago

Question

Recommend the key methods to improve service productivity.

Answered: 1 week ago