Task

Write a program where the program chooses a number between   1   and   10.

A player is then prompted to enter a guess.   If the player guesses wrong,   then the prompt appears again until the guess is correct.

When the player has made a successful guess the computer will issue a   "Well guessed!"   message,   and the program exits.

A   conditional loop   may be used to repeat the guessing until the user is correct.



Related tasks

   Bulls and cows
   Bulls and cows/Player
   Guess the number/With Feedback
   Mastermind


 
DIR
  INITIALIZE
  << { C G R } PURGE RAND 10 * 1 + IP 'R' STO GUESSING
  >>
  GUESSING
  << "Pick a number between 1 and 10." "" INPUT OBJ-> 'G' STO
     IF
       G R ==
     THEN
       CLLCD "You got it!" 1 DISP 7 FREEZE 0 WAIT CLLCD CONTINUE
     ELSE
       IF
         G R <
       THEN
         CLLCD "Try a larger number." 1 DISP 7 FREEZE 0 WAIT GUESSING
       ELSE
         CLLCD "Try a smaller number." 1 DISP 7 FREEZE 0 WAIT GUESSING
       END
     END
  >>
  CONTINUE
  << "Do you want to continue? (0/1)" "" INPUT OBJ-> 'C' STO
     IF
       C 1 ==
     THEN
       INITIALIZE
     ELSE
       CLEAR
     END
  >>
END