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)


import random, strutils
 
randomize()
 
let iRange = 1..100
 
echo "Guess my target number that is between ", iRange.a, " and ", iRange.b, " (inclusive)."
let target = rand(iRange)
var answer, i = 0
while answer != target:
  inc i
  stdout.write "Your guess ", i, ": "
  let txt = stdin.readLine()
  try: answer = parseInt(txt)
  except ValueError:
    echo "  I don't understand your input of '", txt, "'"
    continue
  if answer notin iRange: echo "  Out of range!"
  elif answer < target: echo "  Too low."
  elif answer > target: echo "  Too high."
  else: echo "  Ye-Haw!!"
 
echo "Thanks for playing."