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


 
\ tested with GForth  0.7.0
: RND    ( -- n) TIME&DATE 2DROP 2DROP DROP 10 MOD ;         \ crude random number
: ASK    ( -- ) CR ." Guess a number between 1 and 10? " ;
: GUESS  ( -- n)  PAD DUP 4 ACCEPT EVALUATE ;
: REPLY  ( n n' -- n)  2DUP <> IF CR ." No, it's not " DUP . THEN ;
 
: GAME ( -- )
          RND
          BEGIN   ASK GUESS REPLY  OVER =  UNTIL
          CR ." Yes it was " .
          CR ." Good guess!"  ;
 