Loading...
Loading...
Loading...
In a guessing game the host picks a secret number. The player has at most 5 guesses. After each wrong guess the program says Too low or Too high.
If a guess is right, print Correct on guess k (k is the guess number) and stop reading. If all 5 guesses are wrong, print Out of guesses. The number was s.
Example
Input
42 50 25 40 42 43
Output
Too high Too low Too low Correct on guess 4
The fourth guess is right, so the fifth is never read.
Try the problem first. Open one hint at a time.
A for loop from 1 to 5 gives the guess number. Read one guess per round.
On a correct guess, print the message and break.
After the loop you must know whether the player won. Keep a boolean that the correct branch sets to true.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor