Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have provided you with my code below, I SPECIFICALLY NEED HELP WITH COUNTING LOOP CODE ON THE NUMBER OF GUESSES. #include #include #include using

image text in transcribedimage text in transcribed

I have provided you with my code below, I SPECIFICALLY NEED HELP WITH COUNTING LOOP CODE ON THE NUMBER OF GUESSES.

#include #include #include using namespace std;

class guessGame{ public: int upper_range; int max_guesses; int current_guess; int random_number; bool aboveGuess; bool belowGuess; };

void SetUpperRange(guessGame& currentGame, int upper); //Precondition: State what is true before the function is called. //Postcondition: State what is true after the function has executed. //Description: Describe what the function does.

int GetUpperRange(int level); //Precondition: State what is true before the function is called. //Postcondition: State what is true after the function has executed. //Description: Describe what the function does.

void SetNumGuesses(guessGame& currentGame, int numGuesses); //Precondition: State what is true before the function is called. //Postcondition: State what is true after the function has executed. //Description: Describe what the function does.

int GetNumGuesses(int level); //Precondition: State what is true before the function is called. //Postcondition: State what is true after the function has executed. //Description: Describe what the function does.

void PlayOneRound(const string& name, guessGame& currentGame); //Precondition: State what is true before the function is called. //Postcondition: State what is true after the function has executed. //Description: Describe what the function does.

void GetNextGuess(guessGame& currentGame); //Precondition: State what is true before the function is called. //Postcondition: State what is true after the function has executed. //Description: Describe what the function does.

bool InterpretGuess(guessGame& currentGame); //Precondition: State what is true before the function is called. //Postcondition: State what is true after the function has executed. //Description: Describe what the function does.

void GenerateRandomNumber(guessGame& currentGame); //Precondition: State what is true before the function is called. //Postcondition: State what is true after the function has executed. //Description: Describe what the function does.

int main (){ string name; string yesOrNo = ""; guessGame currentGame;

//get the users name //ask the user if they want to play cout > name; cout > yesOrNo;

while (yesOrNo == "y" || yesOrNo == "Y") //test the while loop condition { //call the Play One Round function and pass the currentGame PlayOneRound(name, currentGame); //play again? cout > yesOrNo; }

//say goodbye to theuser return 0; }

//Function Implementations will go here

void SetUpperRange(guessGame& currentGame, int upper) //Description: sets the upper range for the random number generator. { //sets the upper range value in the current game currentGame.upper_range = upper; }

int GetUpperRange(int level) //Description: Gets the upper range. { //returns the upper range value based on the level if (level == 1) return 10; else if (level == 2) return 50; else if (level == 3) return 100; else cout

void SetNumGuesses(guessGame& currentGame, int numGuesses) //Description: Sets the number of guesses for the current round. { //set the max guesses in the current game, see the SetUpperRange function currentGame.max_guesses = numGuesses; }

int GetNumGuesses(int level) //Description: Gets the number of guesses for the current round { //returns the number of guesses based on the level if (level == 1) return 4; else if (level == 2) return 5; else if (level == 3) return 6;

}

void PlayOneRound(const string& name, guessGame& currentGame) //Description: Play one round of the guess game { int level; int upper; int numGuesses;

//reset above and below to 0 for the new round currentGame.aboveGuess = 0; currentGame.belowGuess = 0;

//describe the levels to the user cout > level;

//get and set the upper range upper = GetUpperRange(level); SetUpperRange(currentGame, upper); //get and set the number of guesses numGuesses = GetNumGuesses(level); SetNumGuesses(currentGame, numGuesses); //generate the random number to be guessed GenerateRandomNumber(currentGame);

//loop header, counting loop for the number of guesses

//currentGame.max_guesses {

//tell the user what guess number they are on //get the next guess //reset above and below to 0 currentGame.aboveGuess = 0; currentGame.belowGuess = 0; //check if the guess is correct if (InterpretGuess(currentGame)) { cout

}

void GetNextGuess(guessGame& currentGame) //Description: get the next guess from the user { //display the information to the user and get the next guess if (currentGame.aboveGuess) //the guess was below the solution { cout > currentGame.current_guess; }

bool InterpretGuess(guessGame& currentGame) //Description: Describe what the function does. { //check if the guess is correct and return true //else tell the user if it was too high and return false //too low and return true //example if (currentGame.current_guess > currentGame.random_number) { cout

void GenerateRandomNumber(guessGame& currentGame) //Precondition: State what is true before the function is called. //Postcondition: State what is true after the function has executed. //Description: Describe what the function does. {

//generate a random number based on the srand((unsigned)time(0)); currentGame.random_number = 1 + rand() % currentGame.upper_range; //cout

}

Assignment purpose: programmer defined functions, call by reference and call by value, simple i/o in C++, simple loop, data types string, int, and bool, simple Class declaration You will write a program that will play a number guessing game. The game will have 3 levels: (1) Beginner - 4 guesses, numbers 1 through 10 (2) Intermediate - 5 guesses, numbers 1 through 50 (3) Advanced - 6 guesses, numbers 1 through 100 The number to guess will be generated with a value between 1 and an upper range depending on the level selected Get one guess at a time and provide feedback to the user, see the sample output below Interact with the user by getting the first name Ask the user if they want to play before getting started (use a while loop) Assume the user will enter an integer for each guess (assume correct data type input) If the user enters a negative number, it will be too low If the user enters a number out of the range, it will be either too high or too low You do not need to force the user to enter a number in the correct range Display the solution number at the end of each round of the game The user should be able to continue to play another round by entering (y or Y) quit by entering (n or N) Use the class below to store the data for each round of guessGame: This is guess number (1) Enter a guess between 1 and 50 : 45 Your guess was too high. - --- -- --- --- ---- --- --- - This is guess number (2) Enter a guess below 45 : 24 You won that round, Tami! Assignment purpose: programmer defined functions, call by reference and call by value, simple i/o in C++, simple loop, data types string, int, and bool, simple Class declaration You will write a program that will play a number guessing game. The game will have 3 levels: (1) Beginner - 4 guesses, numbers 1 through 10 (2) Intermediate - 5 guesses, numbers 1 through 50 (3) Advanced - 6 guesses, numbers 1 through 100 The number to guess will be generated with a value between 1 and an upper range depending on the level selected Get one guess at a time and provide feedback to the user, see the sample output below Interact with the user by getting the first name Ask the user if they want to play before getting started (use a while loop) Assume the user will enter an integer for each guess (assume correct data type input) If the user enters a negative number, it will be too low If the user enters a number out of the range, it will be either too high or too low You do not need to force the user to enter a number in the correct range Display the solution number at the end of each round of the game The user should be able to continue to play another round by entering (y or Y) quit by entering (n or N) Use the class below to store the data for each round of guessGame: This is guess number (1) Enter a guess between 1 and 50 : 45 Your guess was too high. - --- -- --- --- ---- --- --- - This is guess number (2) Enter a guess below 45 : 24 You won that round, Tami

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

Express the given angles in radian measure in terms of . 270

Answered: 1 week ago