' DESSERT2.BAS
' A corrected version of the calorie-counting DESSERT.BAS program.
                                      
                                       ' declare GetData subprogram
DECLARE SUB GetData (array$(), num%, totalCalories%)

CLS
                                       ' print welcome message
PRINT "Welcome to the Dessert Program!"
PRINT                                  ' get user's name
INPUT "Please enter your name:  ", userName$
PRINT                                  ' get number of desserts
PRINT "How many desserts would you like to enter, "; userName$;
INPUT num%
PRINT

DIM desserts$(num%)                    ' dimension string array
                                   
GetData desserts$(), num%, totalCalories%  ' call subprogram
                                    
PRINT "The following is a list of "; userName$; "'s favorite desserts:"
PRINT

FOR i% = 1 TO num%
    PRINT "   "; desserts$(i%)         ' print array contents
NEXT i%

PRINT                                  ' print total number of calories
PRINT "The list contains a total of";  '   with number in flashing red
COLOR 20: PRINT totalCalories%; : COLOR 7
PRINT "calories!"

END

SUB GetData (array$(), num%, totalCalories%)

' The GetData subprogram gets dessert information from the user.

FOR i% = 1 TO num%     ' loop num% times (passed from main program)
    INPUT "   Dessert name:  ", array$(i%)         ' get dessert name
    INPUT "   Calories in dessert:  ", calories%   ' get calories
    PRINT
    totalCalories% = totalCalories% + calories%    ' keep running total
NEXT i%

END SUB                ' return array$ and totalCalories% to main program

