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)


$ include "seed7_05.s7i";
 
const integer: lower_limit is 0;
const integer: upper_limit is 100;
 
const proc: main is func
  local
    var integer: number is 0;
    var integer: guess is 0;
  begin
    number := rand(lower_limit, upper_limit);
    write("Guess the number between " <& lower_limit <& " and " <& upper_limit <& ": ");
    while succeeds(readln(guess)) and number <> guess do
      write("Your guess was too ");
      if number < guess then
        writeln("high.");
      else
        writeln("low.");
      end if;
      write("Try again: ");
    end while;
    if number = guess then
      writeln("You guessed correctly!");
    else
      writeln("You gave up!");
    end if;
  end func;