Create a program that illustrates your understanding of conditions. Create a "High-Low" game which allows the user to play a game with the computer. The game will require input, output, branching and loop behaviors.
The game begins with the computer generating a random integer between 1 and 100. The user will guess a number, and the computer will indicate whether the guess is too high, too low, or correct. This will continue until the user has correctly guessed the computer's number.
I'm thinking of a number between 1 and 100. Guess a number, and I'll tell you if you're too high, too low, or got it right. Good luck! 1) Please enter a number 50 Too low! 2) Please enter a number 75 Too low! 3) Please enter a number 88 Too high! 4) Please enter a number 80 Too low! 5) Please enter a number 84 Too high! 6) Please enter a number 82 Too low! 7) Please enter a number 83 Correct! It took 7 turns.
Once you get the basic form working, see if you can write a program that goes the other direction. The user generates the number, and the computer tries to guess it. A sample run might look like this:
Please think of a number between one and one hundred. I'll guess your number. You tell me if I'm too high, too low, or correct. I guess: 50 too (h)igh, too (l)ow, or (c)orrect? h I guess: 25 too (h)igh, too (l)ow, or (c)orrect? l I guess: 37 too (h)igh, too (l)ow, or (c)orrect? l I guess: 43 too (h)igh, too (l)ow, or (c)orrect? h I guess: 40 too (h)igh, too (l)ow, or (c)orrect? high Sorry, I didn't understand you... I guess: 40 too (h)igh, too (l)ow, or (c)orrect? h I guess: 39 too (h)igh, too (l)ow, or (c)orrect? h I guess: 38 too (h)igh, too (l)ow, or (c)orrect? c I got it! it took 7 turns.