Radio Shack TRS-80 User Manual page 27

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

Advertisement

Chapter 5
Using
(
)
and
the
Order of Operations
Parentheses
play an
important
role
in
computer programming,
just
as in
ordinary
math.
They
are
used
here
in
the
same
general
way,
but
there are
important
exceptions.
l.In
BASIC,
parentheses can enclose operations to be
performed.
Those
operations
which
are
within parentheses
are
performed
before those
not
in
parentheses.
2.
Operations buried deepest within parentheses
(that
is,
parentheses
inside
parentheses)
are
performed
first.
3.
When
there
is
a
"tie"
as
to
which
operations the
Computer
should perform
first
after
it
has
removed
all
parentheses,
it
works
its
way
along the
program
line
from
left
to
right
doing
the multiplication
and
division.
It
then
starts
at
the
left
again
and
per-
forms
the addition
and
subtraction.
NOTE:
INT.
RND
and
ABS
functions
are
performed
before
multiplication
and
division.
(We
haven't talked
about
these
yet,
but
just
to
be
complete
.
.
.
)
4.
A. problem
listed
as
(X) (Y)
will
NOT
tell
the
Computer
to multiply.
X
*
Y
is
for
multiplication.
Example:
To
convert temperature
in
Fahrenheit
to Celsius (Centigrade),
the following
relationship
is
used:
The
Fahrenheit temperature
equals
32
degrees plus
nine-fifths
of the
Celsius
tempera-
ture.
Or,
maybe
you're
more
used
to
the simple
formula
F° =
I-
X
C
+ 32
Assume we
have a
Celsius
temperature of
25°.
Type
in this
program and
RUN
it.
10
REM
*
CELSIUS
TG
FAHRENHEIT CONVERSION
*
20
C =
25
30
f =
(
9/5 )*C
+ 32
40
PRINT
C;
"DEGREES CELSIUS ="
;
F
;"
DEGREES FAHRENHE
I
T
.
"
"FRIENDS."
If
you want
to
be
sure
your problems
are calcu-
lated
cotreetJJr, iuse (
)
around
operations
you
:
;*ant:p£rf/0ri»e&:fEif$L
ItecaH
th« old
memory
aid,
"l#y
Dear
Aunt
y%-.
.Srtly'*?
In
math you
are
supposed to
do
Multipli-
cation
and
Division
first
(from
left
to
righ
i)
,
then
comeback
for
Addition
and
Subtraction
(left
to
:-^\:;";r
--'
:
.;^.
:SS?M^°
-
"
^
:
'-}\.
25

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents