Its a fun game check it out once
The game is computer randomly selects the SECRET number with in the defined range of numbers , here 1 to 52 , and prompts the user to guess the number .
In this program we ask the user to enter any number between 1 to 52 . So user puts up any random number with in the defined range.
If the user number is same as the SECRET number then the game stops ,otherwise,
If the user number is lesser than the SECRET number then ,
It will change the range of the number , that is now user has to select a number between user input number to 52 .
If the user input is greater than the SECRET number then ,
the range of the numbers to select an input from for user will be 1 to user input .
The game continues till the user guesses the correct number .
Here we make sure that the game starts again once it is finished . You can also make it a automated program , that is computer will set the SECRET number and then computer only will try to find it . For that you just need to use random method again and compare it with the target or secret number .
for example :
Suppose computer selects 10 as the secret number
so , user try to guess the secret number between 1 to 52 , let suppose he chooses 38 which is greater than the secret number than the computer prompts user to guess the number from the range 1 to 37
instead if user inputs here 5 in first attempt , then the range would become 6 to 52 .
And in the same way the game continues to be played and the range to select the number keeps on decreasing . There is no limit set to define a select number of attempts to the user .
Pseudo code :
1. Computer randomly selects one secret number ,prompts user to guess it correctly in minimum number of
attempts with in defined range here 1 to 52
2. User inputs any number with in defined range
input number is greater than the secret number than range reduces to 1 to INPUT NUMBER
range reduces to INPUT NUMBER to 52
4. Repeat steps from 2 again