Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that will randomly generate an integer between the numbers 1 and 100, inclusively, and then prompt the user to guess the number.

Write a program that will randomly generate an integer between the numbers 1 and 100, inclusively, and then prompt the user to guess the number. Refer to the tutorial for this lab for help generating a random number. The program should continue until the user guesses correctly. Include the following functions in your program.0

int generateSecretNumber()

This function should generate and return a random integer between 1 and 100, inclusively.

int getUserGuess()

This function should prompt the user to enter his/her guess. Be sure to include the range in the prompt. Input should be validated. Once validated, the user's guess should be returned.

bool correctGuess(int secretNumber, int guess)

This function should determine if the guess is indeed the secret number. If the guess is the secret number, the function should return true, otherwise it should return false.

void guessingGame()

This function should perform any necessary actions to start the game, run the game and complete the game.

main()

Include the following code in function main() to execute the guessing game:

code illustration:

guessingGame(); return 0; 

example of output:

I am thinking of a number between 1 and 100. Can you guess what it is? Enter an integer between 1 and 100: 50 That is not the number. Try again. Enter an integer between 1 and 100: 0 Invalid guess. Please try again. Enter an integer between 1 and 100: 200 Invalid guess. Please try again. Enter an integer between 1 and 100: 45 That is not the number. Try again. Enter an integer between 1 and 100: 2 CONGRATULATIONS! You guessed correctly! 

The prgram should be written in C++!

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

More Books

Students also viewed these Databases questions

Question

socialist egalitarianism which resulted in wage levelling;

Answered: 1 week ago

Question

soyuznye (all-Union, controlling enterprises directly from Moscow);

Answered: 1 week ago