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


/* NetRexx */
 
options replace format comments java crossref savelog symbols nobinary
 
guessThis = (Math.random * 10 + 1) % 1
guess = -1
prompt = [ -
  'Try guessing a number between 1 and 10', -
  'Wrong; try again...' -
  ]
promptIdx = int 0
 
loop label g_ until guess = guessThis
  say prompt[promptIdx]
  promptIdx = 1
  parse ask guess .
  if guess = guessThis then do
    say 'Well guessed!' guess 'is the correct number.'
    leave g_
    end
  end g_
 
return
 