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)


GUESSNUM
    ; get a random number between 1 and 100
    set target = ($random(100) + 1)    ; $r(100) gives 0-99
 
    ; loop until correct
    set tries = 0
    for {
        write !,"Guess the integer between 1 and 100: "
        read "",guess    ; gets input following write
 
        ; validate input
        if (guess?.N) && (guess > 0) && (guess < 101) {
            ; increment attempts
            set tries = tries + 1
 
            ; evaluate the guess
            set resp = $select(guess < target:"too low.",guess > target:"too high.",1:"correct!")
 
            ; display result, conditionally exit loop
            write !,"Your guess was "_resp
            quit:resp="correct!"        
        }
        else {
            write !,"Please enter an integer between 1 and 100."
        }
    }    ; guess loop
 
    write !!,"You guessed the number in "_tries_" attempts."
    quit