' How many cans of cleaner are required for a 12 by 17 ft carpet? ' One can will clean 80 square feet ' LET SQUAREFEET = 12 * 17 LET CANS = SQUAREFEET / 80 PRINT "Size of carpet = ", SQUAREFEET, "Required cans = ", CANS END
Sometimes variables are used inside a program to build up to the
answer.
They are used somewhat like "scratch paper" to hold a step along
the way to the result you want.
The final PRINT
statement might not use them.
Consider the following problem: On Valentine's Day you receive a box of 200 chocolates. The packaging makes the following claims:
You dislike coconut and cherry cream chocolates, and won't eat them.
Will the following program correctly calculate how many chocolates you eat and how many you discard? (Remember that both upper and lower case letters can be used in names for variables, so all the names are correct.)
' Valentine's Day Treat ' LET TotalChocolates = 200 LET DiscardPercent = 25 + 20 LET Discard = TotalChocolates * (DiscardPercent / 100) LET Eaten = TotalChocolates - Discard PRINT "You will eat", Eaten, "chocolates and throw away", Discard, "chocolates." END