A friend proposes the following guessing game: He chooses an integer between 1 and 100, inclusive, and you repeatedly try to guess his number. He tells you whether each incorrect guess is higher or lower than his chosen number, but you are allowed at most one high guess overall.You win the game when you guess his number correctly. You lose the game the instant you make a second high guess. What is the minimum number of guesses in which you can guarantee you will win the game?
The approach should be to choose a small number so that there is good chance that the chosen number is higher and thus we can keep guessing. The number shouldn't be so small that if the chosen number is very high (say 99) then it will take too many guesses. We would like to maintain a gap between our guesses in such a way that if the chosen number is smaller than we can just guess all the numbers between our preceding and present guess with minimum effort.
Using trial and error to optimise that particular number, the answer can be arrived at 14 guesses starting with the first guess as 14.
Consider the following scenario :
Our first guess is 14. If the chosen number is lower than we will start guessing from 1 to 13. The maximum it will take is 14 guesses if the chosen one is 13.
If the chosen number is higher than our next guess would be 27. If this is high then we will guess between 15 and 26. The maximum number of guesses will happen if the chosen number is 26. This will take 14 guesses in total (14,27,15,....,26).
Similarly, if we continue to guess low then our next guesses would be 39,50,60,69,77,84,90,99 and 100. As it can be seen, even if 100 was the chosen number, the number of guesses is less than 14, thus guranteeing our success.
A friend proposes the following guessing game: He chooses an integer between 1 and 100, inclusive,...
Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, allow the user to try up to 10 times to guess the number, and tell the user if each guess is too high, too low, or correct. The actual game portion must be a function...you can use more than one function in your program. The amount...
Hello, Could you please explain how I would complete this program with input validation to ensure that an error message will not appear if the user enters something other than an integer that is not 1-100 and later if they enter anything other than yes and no? Here is the program: Write a program that plays the Hi-Lo guessing game with numbers. The program should pick a random number between 1 and 100 (inclusive), then repeatedly promt the user to...
How can I do this program complete with input validation so that the computer prompts the user to enter a number 0 through 100 if he/she guesses anything lower than 0, a floating point number, or other characters? And later, prompts the user to enter yes or no if he/she enters anything else when the program prompts the user to play again? Write a program that plays the Hi-Lo guessing game with numbers. The program should pick a random number...
Write a game application that generates a random number between 1 and 1000 (inclusive) and prompts the user for a guess. Use the pseudorandom number generator, the Random class. When the user guesses the correct number, say so, and display how many guesses the user required to guess correctly. Allow the user to play multiple times by asking the user if the user wants to continue playing. Guess my number between 1 and 1000 => 500 Too high...
Python Program
Python: Number Guessing Game Write a Python function called "Guess.py" to create a number guessing game: 1. Function has one input for the number to Guess and one output of the number of attempts needed to guess the value (assume input number will always be between 1 and 1000). 2. If no number was given when the function was called, use random.randint(a,b) to generate a random number between a=1 and b=1000. You will also need to add an...
Write a Java application program that plays a number guessing game with the user. In the starter code that you are given to help you begin the project, you will find the following lines of code: Random generator = args.length == 0 ? new Random() : new Random(Integer.parseInt(args[0])); int secret = generator.nextInt(100); You must keep these lines of code in your program. If you delete these lines, or if you change thse lines in any way, then your program...
Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually kind of confusing to me. I keep getting lost in all of the words even though these are supposed to instruct me as to how to do this. Can I please get some help as to where to start? Word guessing game: Overview: Create a game in which the user has a set number of tries to correctly guess a word. I highly recommend...
Using C++ language
P2-4 Write a program that randomly generates an integer and then prompts the user to guess the number. If the user guesses the number correctly, the program outputs an appropriate message such as "You win!" and terminates. Otherwise, the program checks and tell the user whether the guessed number is less or greater than the target number and then prompts him for another try. However, the program gives the user five tries only to guess the correct...
USE JAVA
Problem 1: Guess a Number You are writing a program for a number guessing game. For playing "Guess a Number", the program will generate a number for player to guess from within a range specified by the player. The program will take as input the lowest number in the range and the highest number in the range from the player, and then a series of guesses of the form: <n,>n, = n, where n is the number guessed....
Design and implement a class for a one person guessing game as
described on page 30, Chapter 1, Programming Problem 7 of the
textbook. CSCI 2421 HW1.jpg
Submit header file guess.h, implementation file guess.cpp, main
function file main.cpp that asks initial seed number, and prints
three sequential numbers generated by the program. You need to
include a makefile, and Readme file
pseudocode version UF comments in your code. 6. Exercises 6, 7, and 8 ask you to specify methods for...