Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Program This program is a number guessing game. The way the game is played is this: The program asks the player to select a

C++ Program

This program is a number guessing game. The way the game is played is this: The program asks the player to select a range of numbers from 1 to a positive integer. It will use the random number generator to generate a magic number within this range. The program should then give the player five chances to guess the value of the magic number. When the player enters the guess value, the program will report if the guess is the magic number or if the number is too high or too low. If the player guesses the number, the program should print a congratulatory message and report the number of tries it took to guess the number. If the player does not guess the number in five tries, the program stops the guessing loop, and tells the player the value of the magic number.

Use functions to build this program, using a Functions.h file for the prototypes and a Functions.cpp file for the function implementations. You will write six functions.

  1. WriteHeader, displays your course header information to the player. This includes your name, program number, course and section.

  1. SeedRNGen, is to perform the task of seeding the random number generator that will be used in generating numbers. Remember, the seed value for the generator is used in a mathematical calculation when the random numbers are produced. Each seed will cause the generator to produce a unique set of values when rand() is called. Please refer to the section in the text that demonstrates this. This function, SeedRNGen asks the player for the seed value, which should be a positive int. The value is passed to the srand() function. This function must be called by the program ONLY ONCE. The SeedRNGen function has no inputs and returns nothing.

  1. AskRange, obtains the positive number that is the top value for the guessing range. That is, the value you enter is included in the range. If you enter 25, the magic number will be generated between 1 and 25, inclusive. Nothing is passed to this ask function, and it returns an integer.

  1. ValidateGuess is passed the range value and the guess and checks if the guess is within the range. It is called from GuessingGame and returns a bool to signify whether the guess is inside the range or not. Also check that the guess is greater than or equal to 1.

  1. The actual guessing game is handled in GuessingGame. The range is passed to GuessingGame, which contains the logic obtaining the magic number. It also contains the guessing loop for the five guesses, which includes asking the player for a guess.

It also displays the number of guesses available for each time the player is asked to guess. When the player guesses, the function calls ValidateGuess . If the guess is not in a valid range, it tells the player that the guess is out of range and to guess again. An out-of range guess is not deducted from the number of guesses.

The function shows a congratulatory message or shows the magic number if the player is out of guesses.

  1. ObtainMagicNumber, is called from the GuessingGame function. This function is passed the top range, and uses the rand() random generator to obtain a value between 1 and the top range number. This number is returned to the GuessingGame function.

Flow of the program: The main function will declare any variables that are needed and calls the WriteHeader function, then seeds rand by calling SeedRNGen. It then opens a do while loop (play loop) and asks the player for the top value of the range by calling AskRange. The program then calls the function that actually runs the guessing game, GuessingGame, When the number is guessed, or the player has lost, the control of the program returns to main. Ask the player if they want to try another. If the answer is positive, loop up to the beginning of the play loop. If negative, drop out of the loop and say goodbye.

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

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

Students also viewed these Databases questions

Question

Question May I set up a Keogh plan in addition to an IRA?

Answered: 1 week ago