variable in much the same way numeric variables are stored. You
can also use variable names to represent strings, just as you use
them to represent numbers. When you put the dollar sign ($) after
the variable name, it tells the computer that the name is for a
string variable, and not a numeric variable.
Type NEW and press RETURN to clear your computer’s memory,
then type in the program below:
10 A$ = “COMMODORE “
20 X = 128
30 B$ = “ COMPUTER”
40 Y = 1
50 ? “THE ”A$;X;B$“ IS NUMBER ”Y
See how you can print numeric and string variables in the same
statement? Try experimenting with variables in your own short
programs.
You can print the value of a variable in DIRECT mode, after the
program has been RUN. Type ?A$;B$;X;Y after running the
program above and see that those three variable values are still
in the computer’s memory.
If you want to clear this area of BASIC memory but still leave your
program intact, use the CLR command. Just type CLR<RETURN>
and all constants, variables and strings are erased. But when you
type LIST, you can see the program is still in memory. The NEW
command discussed earlier erases both the program and the
variables.
SAMPLE PROGRAM
Here is a sample program incorporating many of the techniques
and commands discussed in this section.
This program calculates the average of three numbers (X, Y and
Z) and prints their values and their averages on the screen. You
can edit the program and change the calculations in line 10
through 30 to change the values of the variables. Line 40 adds
the variables and divides by 3 to get the average. Note the use of
parentheses to tell the computer to add the numbers before it
divides.
3-25