The variables are switched at line 80.
80
X$=A$:A$=B$:B$=X$
Program Statement
X$=A$
A$=B$
B$=X$
Memory
X$
A$
~
035
3 3 5
3 5 5
353
X$ acts
as
a storage string to prevent losing the contents of an entire string.
Without
X$, the original contents of A$
would
be
written
over and the contents of
B$
would
be
written
back into itself:
Program Statement
A$=B$
B$=A$
Memory
A$
B$
3 5
5 5 1ncorrect
5 5
Later in the program
we
will
need ta know if the variables have been
switched.
We
therefore set a marker ta signal
that
A$
and B$ have been switched.
Use variable
$ for this: $ remains °if the variables have
not
been switched. If the
variables are switched, set
$=1.
Later, at line 1140, if $=1
it
signais that a nega-
tive sign
must
be concatenated ta the front of
C$.
Line 90 sets $=1 if the values of
A$
and B$ have been switched.
9(1
8=1
Remember that after the strings are properly switched, a value of 1
is
assigned ta S to signal that the numbers have been switched and a negative
answer
is
needed. The negative answer
is
obtained by concatenating a negative
sign to the
front
of
the answer before
it
is
printed. This occurs at statement 1140,
where
C$
equals the answer to the problem.
1140
IF
8=1
THEt..,
C$="-"+C$
204