Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Program in C Overview: Write a simple game to be played between the computer and a single user. The user defines a sample

Write a Program in C

Overview: Write a simple game to be played between the computer and a single user. The user defines a sample space for the computer to choose a secret number from. The user then attempts to guess the number and is told too high or too low after each guess. (1, 2, 3, 5, 6, 8, 10, 12, 13)

Write a program that accomplishes all of the following:

Greets the user and explains the programs function.

The user will supply an upper bound for a game where the computer will pick a secret random number between 1 and that number (inclusive).

The computer will then continually accept input until the user guesses the secret number, giving direction of too high or too low after each guess.

Accept an integer input from the user. Assume that the user provides a valid numeric input that will fit in the standard int type. However, check to make sure the input was greater than 1 - otherwise, ask for the input again.

Generate a secret random number (hint: seed the random number generator based on the current time) in the range 1 - x, where x is the number gathered from the user in the previous step. Do not display the secret number to the user.

Accept integer input from the user for their guess of what the secret number might be.

If the users guess is correct, print a message saying that they guessed the number correctly and end the program.

If the users guess is lower than the secret number, print a message indicating their guess was too low, and accept another input.

If the users guess is higher than the secret number, print a message indicating their guess was too high, and accept another input.

If the user guesses a number outside the original range, or at any point makes a guess that contradicts the computers feedback, they lose and the game should end.

Example: Range is 1-100. Secret number is 53. User guesses 120. User loses since the input is outside the given range.

Example: Range is 1-100. Secret number is 22. User guesses 50. Computer indicates guess is too high. User guesses 55. User loses since they ignored the computers instruction about 50.

Example: Range is 1-100. Secret number is 49. User guesses 35. Computer indicates guess is too low. User guesses 70. Computer indicates guess is too high. User guesses 30. User loses since they ignored the computers previous instruction about 35.

Use functions where appropriate. Do not put all of your code in the main function.

Test your program thoroughly. For testing purposes, you could add a print message showing what the secret number is, so that you can make guesses knowing what the output should be. Remove any such print message before turning in the final version of your program.

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_2

Step: 3

blur-text-image_3

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

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

Students also viewed these Databases questions

Question

LO1 Understand risk management and identify its components.

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago