Solution to Lesson 4
( This code can be found at .\tutorial\Lesson4\MenuLoop.bas )
'--------------------------------
'- Variable declaration section -
'--------------------------------
DIM Menu% ' the user selected menu option
DIM Value! ' value the user entered
'----------------------------
'- Main program begins here -
'----------------------------
DO ' begin main program loop
CLS ' clear the screen
PRINT " -- Conversion Utility --" ' display menu to user
PRINT
PRINT "1. Convert Fahrenheit to Celsius"
PRINT "2. Convert inches to millimeters"
PRINT "3. End program"
PRINT
INPUT " Enter selection > ", Menu% ' get user's choice
IF Menu% = 1 THEN ' did user select option 1?
INPUT "Enter temperature in Fahrenheit to convert > ", Value! ' yes, get user input
PRINT Value!; "degrees F ="; 5 * (Value! - 32) / 9; "degrees C" ' display results
PRINT "Press any key to return to menu ..."
SLEEP ' wait for a key press
ELSEIF Menu% = 2 THEN ' no, did user select option 2?
INPUT "Enter the number of inches to convert > ", Value! ' yes, get user input
PRINT Value!; "inches ="; Value! * 25.4; "millimeters" ' display results
PRINT "Press any key to return to menu ..."
SLEEP ' wait for a key press
END IF
LOOP UNTIL Menu% = 3 ' leave when user selects option 3
SYSTEM ' return control to operating system