P3: Higher/Lower solution

COMP 14-091 Summer Session I 2000

Here is my HigherLower.java file.

I chose to use 3 loops - one nested inside the other. It continues to run as long as the user wants to play again. The outermost loop is a do loop that has 3 parts to its body:

  1. pick a secret number
  2. run the game
  3. ask if they want to play again
The second step above is actually another do loop. This loop runs as long as the user hasn't guessed correctly AND they haven't entered a 0. This loop's body is broken down into these steps:
  1. prompt for a guess
  2. verify that guess is valid
  3. determine what guess means
It turns out that step 2 in this second do loop is another loop. This time it's a while loop. This while loop runs as long as the guess that the person enters isn't valid (isn't in the range [0, 100]).

Here's the pseudocode outline for my program solution:

do
{
    pick a secret number
    do
    {
        prompt for guess
        while (guess is not valid)
        {
            prompt for another guess
        }
        determine if guess is lower, higher, correct, or 0
    } while (guess isn't correct AND guess isn't 0)
    prompt user to play again
} while (user wants to play again)