Task

Write a game (computer program) that follows the following rules:

 The computer chooses a number between given set limits.
 The player is asked for repeated guesses until the the target number is guessed correctly
 At each guess, the computer responds with whether the guess is:
 higher than the target,
 equal to the target, 
 less than the target,   or
 the input was inappropriate. 


Related task

   Guess the number/With Feedback (Player)


/* NetRexx */
options replace format comments java crossref symbols nobinary
 
parse arg lo hi .
if lo = '' | lo = '.' then lo = 1
if hi = '' | hi = '.' then hi = 100
if lo > hi then parse (hi lo) lo hi -- make sure lo is < hi
rg = Random()
tries = 0
guessThis = rg.nextInt(hi - lo) + lo
 
say
say 'Rules:  Guess a number between' lo 'and' hi
say '        Use QUIT or . to stop the game'
say '        Use TELL to get the game to tell you the answer.'
say
say 'Starting...'
say
 
loop label g_ forever
  say  'Try guessing a number between' lo 'and' hi
  parse ask guess .
  select
    when guess.upper = 'QUIT' | guess = '.' then do
      say 'You asked to leave the game.  Goodbye...'
      leave g_
      end
    when guess.upper = 'TELL' | guess = '.' then do
      say 'The number you were looking for is' guessThis
      end
    when \guess.datatype('w') then do
      say guess 'is not a whole number.  Try again.'
      end
    when guess = guessThis then do
      tries = tries + 1
      say 'Well guessed!' guess 'is the correct number.'
      say 'It took you' tries 'tries.'
      leave g_
      end
    when guess < lo then do
      tries = tries + 1
      say guess 'is below the lower limit of' lo
      end
    when guess > hi then do
      tries = tries + 1
      say guess 'is above the upper limit of' hi
      end
    when guess < guessThis then do
      tries = tries + 1
      say guess 'is too low. Try again.'
      end
    when guess > guessThis then do
      tries = tries + 1
      say guess 'is too high. Try again.'
      end
    otherwise do
      say guess 'is an unexpected value.'
      end
    end
  end g_
 
return
 