Liberty BASIC - Help Online

HILO.BAS
Complete listing for HILO.BAS
 
Here is the complete listing for HILO.BAS so that you can just copy and paste it into Liberty BASIC to run it.
 
    ' Here is an interactive HI-LO
    ' Program
 
[start]
    guessMe = int(rnd(1)*100) + 1
 
    ' Clear the screen and print the title and instructions
    cls
    print "HI-LO"
 
    print
 
    print "I have decided on a number between one"
    print "and a hundred, and I want you to guess"
    print "what it is.  I will tell you to guess"
 
    print "higher or lower, and we'll count up"
    print "the number of guesses you use."
 
    print
 
[ask]
    ' Ask the user to guess the number and tally the guess
    input "OK.  What is your guess?"; guess
 
    ' Now add one to the count variable to count the guesses
    let count = count + 1
 
    ' check to see if the guess is right
    if guess = guessMe then goto [win]
    ' check to see if the guess is too low
    if guess < guessMe then print "Guess higher."
 
    ' check to see if the guess is too high
    if guess > guessMe then print "Guess lower."
 
    ' go back and ask again
    goto [ask]
 
[win]
    ' beep once and tell how many guesses it took to win
    beep
    print "You win!  It took"; count; "guesses."
 
    ' reset the count variable to zero for the next game
    let count = 0
 
    ' ask to play again
    input "Play again (Y/N)"; play$
    if instr("YESyes", play$) > 0 then goto [start]
 
    print "Press ALT-F4 to close this window."
 
    end


Copyright (C) 2005 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/