space after the N of ON or forgot the period and the space before
TOO BAD!. Those spaces are important. Practice with another string
variable input:
30 DIM NAME$ (1)
170 PRINT "BY THE WAY.. WHAT IS YOUR NAME";
180 INPUT NAME$
190 PRINT "WELL, "; NAME$;", I BET YOU WOULD LIKE TO KNOW
HOW MUCH YOU WON . FIRST YOU HAVE TO ANSWER A QUESTION . "
Run the program. Even though you typed in a full name, the computer
printed only the first initial. That happened because the area
dimensioned in RAM memory for the name was too small. Most
people's names are longer than one character. Change line 30 to a
more reasonable number of spaces and run the program:
30 DIM NAME$ (25)
RUN
Inputting Numeric Variables
So far you have been working with alphanumeric string variables-
variables composed of letters, numbers, or both. For instance, the
computer would accept the name R2-D2 or 007 as a string variable.
However, the number name would be used only as a name, not as a
number in any math problems. Now try some numeric variables that
can be used in mathematical calculations. Numeric variables do not
need a DIM command or a dollar sign. Enter the following program
lines:
20O PRINT:PRINT "HOW OLD ARE YOU";
210 INPUT AGE
220 PRIZE=AGE*1000
23O PRINT : PRINT "YOU HAVE JUST WON $" ; PRIZE ;" FROM THE
LOTTERY. YOU CAN COLLECT DURING OFFICE HOURS."
In this program, the age that you enter is stored in the numeric
variable called AGE. Line 220 creates another variable called PRIZE.
Line 220' allows the computer's built-in calculator to calculate the
prize money, which is $1000 multiplied by the age of the winner. (To
the computer, * means multiply.) The program does the math for you
and stores the answer in PRIZE. Line 230, which places the numeric
value inside the PRINT statement in the same manner as string
variables, tells you what the answer is.
45