Lab 1 “One in a Thousand” solved

$30.00

Category: Tags: , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (15 votes)

Write a program to play a number guessing game.

The user thinks of a number between 1 and 1000 andyour program asks question to figure out what the number is. (e.g., “Is the number you are thinking of less than 230?”, use only the less than operator).

All guesss should be of this form, i.e., “Is the number you are thinking of less than xyz?”where xyz is a number between 1 and 1000.

The correct number should be passed as a command-line parameter to your program, which should be called “guess.exe”. So for example, if the true numberwere supposed to be 473, then you would run your program with the command “guess.exe 473”.

If the provided parameters i was not between 1 and 1000 inclusive, your program should output an error message: “Invalid number!” and exit.

Your program should be able to identify the number after asking no more than ten questions.

Once your program has determined the number (say for example it was 473), it should print to standard output the following message: “Your number is 473!”and exit.Hint: You will want to keep track of the minimum and maximum possible values of the number the user thought of at each stage.

It is up to you to determine which number to guess/ask a question about which will minimize the possible interval in which the true number lies.

If the questions are asked properly, then the minimum and maximum possible values of the number will eventually become equal, in which case, the program will be able to determine what the true number was and print out the “Your number is …” message.