Question
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
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. Again, create a hierarchy outline (see pg. 249) for the program and place it in the comments section at the top of the app. Its not required to break the functions out into header/implementation files, but you can if you like. Your choice.
Guess number program from chapter 4
#include #include #include
using namespace std;
int main(){ int upper_limit = 100; //Print the title de program and instructions cout cout //get the random number 1 and the the upper limit srand(time(nullptr)); int number = rand() % upper_limit; ++number;
// Only to test the program //cout
//Try until the user guesses what the random number is int count = 1; int guess = 0; while (guess != number){ cout cin >> guess;
if (guess upper_limit){ cout }else if (guess cout }else if (guess > number + 10){ cout }else if (guess cout }else if(guess > number){ cout }else{ cout } ++count; } cout }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started