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)


MODULE guessf;
 
IMPORT  InOut, Random, NumConv, Strings;
 
VAR     number, guess           : CARDINAL;
        input                   : Strings.String;
        OK, Done                : BOOLEAN;
 
BEGIN
  number := Random.nr (1000);
  InOut.WriteString ("I have chosen a number below 1000; please try to guess it.");
  InOut.WriteLn;
  REPEAT
    REPEAT
      InOut.WriteString ("Enter your guess : ");        InOut.WriteBf;
      InOut.ReadString (input);
      NumConv.Str2Num (guess, 10, input, OK);
      IF  NOT OK  THEN
        InOut.WriteString (input);
        InOut.WriteString (" is not a valid number...");
        InOut.WriteLn
      END
    UNTIL  OK;
    InOut.WriteString ("Your guess is ");
    IF  number = guess  THEN
      Done := TRUE;
      InOut.WriteString ("spot on!")
    ELSE
      Done := FALSE;
      IF  guess > number  THEN
        InOut.WriteString ("too high.")
      ELSE
        InOut.WriteString ("too low.")
      END
    END;
    InOut.WriteLn
  UNTIL  Done;
  InOut.WriteString ("Thank you for playing; have a nice day!");
  InOut.WriteLn
END guessf.