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


 
PROGRAM GUESS_NUMBER
 
!
! for rosettacode.org
!
 
BEGIN
 
  RANDOMIZE(TIMER)
  N=0
  R=INT(RND(1)*100+1)  ! RND function gives a random number from 0 to 1
  G=0
  C$=""
 
  WHILE G<>R DO
    INPUT("Pick a number between 1 and 100";G)
    IF G=R THEN
        PRINT("You got it!")
        N+=1
        PRINT("It took";N;"tries to pick the right Number.")
    ELSIF G<R THEN
        PRINT("Try a larger number.")
        N+=1
    ELSE
        PRINT("Try a smaller number.")
        N+=1
    END IF
  END WHILE
END PROGRAM
 