' Filename: C22AGEWT.BAS
'
' Program to compute age in dog years and weight on the moon
' to illustrate functions and subroutine calls.


' Subs & Functions (6) total

DECLARE SUB ShowMoonWeight ()
DECLARE FUNCTION DogAgeCalc! (age!)
DECLARE FUNCTION MoonWeightCalc! (weight!)
DECLARE SUB DisplayMenu ()
DECLARE SUB ShowDogAge ()
DECLARE SUB Want.to.End ()


COLOR 7, 1      ' White text on blue background
CLS

DO
  DisplayMenu   ' Call subroutine that dispalys menu
  SELECT CASE choice
    CASE 1:     ' Compute dog age
      ShowDogAge        ' Call the dog age subroutine
    CASE 2:
      ShowMoonWeight    ' moon weight subroutine
    CASE 3:
      Want.to.End
    END SELECT
  LOOP UNTIL (choice = 3)  ' Keep running menu until user wants
                           ' to quit

SUB DisplayMenu
SHARED choice

CLS

PRINT
PRINT "Do you want to:"
PRINT
PRINT "1.  Compute your age in dog years"
PRINT "2.  Compute your weight on the moon"
PRINT "3.  Quit this program"
PRINT
INPUT "What is your choice"; choice


END SUB

FUNCTION DogAgeCalc! (age!)

DogAgeCalc! = age / 7   ' A dog year is seven of yours


END FUNCTION

FUNCTION MoonWeightCalc! (weight!)

  moon.factor = (1 / 6)         ' The moon is 1/6th earth's gravity
  MoonWeightCalc! = moon.factor * weight

END FUNCTION

SUB ShowDogAge


CLS
PRINT
INPUT "How old are you"; age
dog.age = DogAgeCalc!(age!)     ' Call dog age calculation procedure
PRINT
PRINT "Your age in dog years is only"; dog.age; "!"
PRINT "You're younger than you thought..."
PRINT

PRINT "Press any key to return to the main menu..."

DO
  a$ = INKEY$   ' Wait until they press a key
LOOP WHILE (a$ = "")    ' Keep looping until they press a key

END SUB

SUB ShowMoonWeight

CLS
PRINT
INPUT "How much do you weigh"; weight
moon.weight = MoonWeightCalc!(weight!)  ' Call moon weight
                                        ' calculation procedure
PRINT
PRINT "Your weight on the moon is only"; moon.weight; "pounds!"
PRINT "You are light enough to fly! (on the moon...)"
PRINT
PRINT "Press any key to return to the main menu..."

DO
  a$ = INKEY$           ' Wait until they press a key
LOOP WHILE (a$ = "")    ' Keep looping until they press a key

END SUB

SUB Want.to.End
'
' Will decide if user wants to leave or not
'

CLS
PRINT "You are about to quit"
INPUT "Continue (Y/N)", Ans$

IF Ans$ = "Y" OR Ans$ = "y" THEN CLS : PRINT "Please Wait..": CHAIN "moneycga" ELSE DisplayMenu


END SUB

