Radio Shack TRS-80 User Manual page 20

Micro computer system
Hide thumbs Also See for TRS-80:
Table of Contents

Advertisement

Putting the Beast
to
Work
We
will
now
use the
Computer
for
some
very simple problem-solving.
That means
using
equations
oh
-
panic.
But
then,
an equation
is
just a
little
statement
that says what's
on one
side
of the equals
sign
amounts
to the
same
as
what's
on
the other
side.
That
can't get
too
bad
(it
says here).
We're going
to use that
old
standby
equation,
"Distance
traveled
equals
Rate
of
travel
times
Time
spent
traveling."
If
it's
been
a
few
years,
you
might
want
to
sit
on
the
end
of a
log
and
contemplate
that for
awhile.
To
shorten the equation,
lets
choose
letters (called variables)
to
stand
for the three
quan-
tities.
Then
we
can
rewrite the
equation
as
a
BASIC
statement acceptable
to the
TRS-80:
40
D
=
R
*
T
What's
that
40
doing
there? That's the
program
line
number.
Remember,
every step
in
a
pro-
gram
has to
have one.
We
chose 40, but another
number would
have
done
just
as well.
The
extra spaces
in
the
line
are
there
just
to
make
the
equation
easier
for us
to
read;
the
TRS-80
ignores
them.
Later,
when you
write very long
programs,
you'll
probably
want
to eliminate
extra
spaces,
because they take
up
memory
space.
For now,
they
may
be
helpful,
so
leave
them
in.
We
can use
any
of the
26
letters
from
A
through Z
to identify
the values
we know
as
well
as
those
we
want
to
figure out.
Whenever you
can,
it's
a
good
idea to
chose
letters
that
remind
you
of the things
they stand
for
like
the
D, R, and
T
of
the Distance,
Rate,
Time
equation.
To
further
complicate
this
very simple example,
we
will
point
out
now
that
there's
an
optional
way
of writing the equation, using the
BASIC
statement
LET:
40
LET D
=
R
*
T
This use of
LET
reminds
us that
making
D
equal
R
times
T
was our
choice, rather
than an
eternal truth
like
1
+
1
=
2,
Some
computers
are fussy,
and
always
require the use
of
LET
with
programmed
equations.
Your TRS-80
says,
"Have
it
your way".
Okay
let's
complete
the
program.
Assume:
Distance
(in
miles)
=
Rate
(in
miles per
hour) multipled
by
Time
(in
hours).
How
far
is it
from Boston
to
San Diego
if
a
jet
plane
traveling at
an average speed of
500
miles per
hour makes
the
trip in
6
hours?
18
Remember,
we
have
to
use the *
for multqriica-
tton.
.
,'
."/.
Here's
what
line
40 means
to
t&e
Computer;
"Tate
the value^of
Rand
T^
multiply
mem
together^
arul
assign
the
resulting value
to
the
vari-
able
IX
So
until
further notice,
5
fe
equalto
the
result
of
R
times
T."
We
could not
reverse the
equation
and
write,
f^T^
p. This
would have
no
meaning
for
the;
Computer.
Hemember,
the
left
hand
side
of
the
1
equation
is
reserved for variable
names
(which-
:
;eyer
'tetter
we
choose).
The
right
hand
side
iatihe--.
piaee to
put
math
expressions involving
numbers,
operators,
and
known
variables.
'
(Yes,
I
ktiow^ybu
aim'd^'ttiat'oheln
your.'
:
hS
hut
that's
not
the point!)

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents