Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I refactor this application, create a hierarchy outline for it, and also add the logic into these functions? Here is the prompt for

How do I refactor this application, create a hierarchy outline for it, and also add the logic into these functions?

Here is the prompt for it.

Refactor the Guess Number application we did in chapter 4 so that you move the logic into functions named get_random_number(), get_user_guess() and check_guess(). Use your best judgement to decide what code to move into which function, and also how to call it. Also, create a hierarchy outline for the program and place it in the comments section at the top of the app.

Here is my starting code.

#include

#include

#include

// Reagan Parker, 01/31/20, csc143

using namespace std;

int main() {

int upper_limit = 100;

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 (true) {

int guess;

cout << "Your guess: ";

cin >> guess;

if (guess < 1 || guess > upper_limit) {

cout << "Invalid guess. Try again. ";

}

if (guess < number) {

if (guess < (number - 10) || guess > (number + 10)) {

cout << "Too low. Guess Again! You're getting too cold! ";

}

else

cout << "Too low. You're getting warm! ";

}

else if (guess > number) {

if (guess < (number - 10) || guess > (number + 10)) {

cout << "Too high. Guess Again! You're too cold! ";

}

else {

cout << "You guessed it in " << count << " tries. ";

}

++count;

++guess;

}

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_2

Step: 3

blur-text-image_3

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

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

What did they do? What did they say?

Answered: 1 week ago