Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with this program please 2. Guessing game. Create a project titled Lab4 Guess with a single file titled guess.cpp Program the following game. The

Help with this program please
image text in transcribed
2. Guessing game. Create a project titled Lab4 Guess with a single file titled guess.cpp Program the following game. The computer selects a random number between 1 and 100 and asks the user to guess the number. If the user guesses incorrectly, the computer advises to try larger or smaller number. The guessing repeats until the user guesses the number. The dialog should look as follows (user input is shown in bold): Guess a number between 1 and 100: 50 try larger: 75 try smaller: 68 try larger: 71 you got it! For your program, you need to use predefined randomization functions rand) and srand() as well as the time function time) o Function time) returns current time (as kept by the computer) in the number of seconds passed since midnight, January 1, 1970. You need to include ctime to use this function. The function takes one argument but for this assignment the argument value is a special named constant nullptr. Check this program for an example usage o To use functions rand() and srand) you need to include cstdlib Function srand) initializes the random number generator of the program. It takes a single integer argument. The value passed to srand() determines the values output by rand(). This value is called seed rand) takes no arguments. Every time rand) is invoked it returns an integer value between 0 and constant RAND MAX defined in cstdlib. Note that the sequence of values returned by repeated calls of rand) is uniquely determined by the seed passed to srand ( ). That is, if srand ( ) 1s passed the same seed, rand ( ) 1s going to return the same sequence of numbers. This is helpful for debugging. Check this program for an example of random number manipulation. Hints: Use fixed values of the seed for your initial debugging, use the output of time) as an unpredictable seed to start the guessing game once you debugged your program. Note that random value produced by rand ( ) is out of the required range of 1-100. To get the random number into the required range, remainder it by 100 (that puts the number in 0-99 range) and then add one. Do not put srand() inside the loop or anywhere, where it may be invoked more than once it resets the random number generator. Milestone: implement the first assignent (scientific calculator). Make sure your program adheres to proper programming style. Submit your project to the subversion repository. Do not forget to verify your submission on the web

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

Microsoft Outlook 2023

Authors: James Holler

1st Edition

B0BP9P1VWJ, 979-8367217322

More Books

Students also viewed these Databases questions

Question

How is the recovery rate of a bond usually defined? AppendixLO1

Answered: 1 week ago