Commodore 64 User Manual page 47

Hide thumbs Also See for 64:
Table of Contents

Advertisement

If you did everything as shown, you should get the following result
printed on the screen.
RUN
X% =
15
X
=
23
.5
THE SUM OF Xj + X = 38.5
READY
We've put together all the tricks learned so far to format the display
as you see it and print the sum of the two variables.
In lines 10 and 20 we assigned an integer value to X% and assigned a
floating point value to X. This puts the number associated with the vari-
able in its box. In line 30, we assigned a text string to X$. Line 40
combines the two types of PRINT statements to print a message and the
actual value of X% and X. Line 50 prints the text string assigned to X$
and the sum of X% and X.
Note that even though X is used as part of each variable name, the
identifiers % and $ make X%, X, and X$ unique, thus representing
three distinct variables.
But variables are much more powerful. If you change their value, the
new value replaces the original value in the same box. This allows you
to write a statement like:
X = X + 1
This would never be accepted in normal algebra, but is one of the
most used concepts in programming. It means: take the current value of
X, add one to it and place the new sum into the box representing X.
IF ... THEN
Armed with the ability to easily update the value of variables, we can
now try a program such as:
37

Hide quick links:

Advertisement

Table of Contents
loading

Related Products for Commodore 64

Table of Contents