EasyManua.ls Logo

Radio Shack TRS-80

Radio Shack TRS-80
236 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
70
P.
sGDTO
10
80
P.
"CHOP
IT
DOWN
AND
TAKE
IT
HOME!"
RUN it.
(After
you've
tried a
few
values
for
Distance
and
Angle,
use
Distance=16
and
Angle=60.)
Hit
| BREAK]
to
get out
of the
program.
A
few
notes
on how
the
program
works:
Line
30
gives
X
the
value of
angle A.
This is
necessary
because
the
subroutine
needs
an
X-
input.
Control
is
then
transferred
to 30320,
the
beginning
of
the
tangent
subroutine,
which
returns
a value
for
Y
=
TAN(X).
Line 40
computes
the height
as D
times Y
(D times
the
Tangent
of
the
Angle),
and
then
rounds
the
answer
off
to
the
nearest
integer.
Line
50
checks
to
see
whether
we've found
our tree.
If
we have,
program
control
goes to
Line
80,
where a
suitable
message is
printed.
Otherwise, Line 60
tells us to
find
a new
tree
and line
70
starts
the
program
over
again.
But
you
can't find
an
extension
cord
that's long
enough.
And you
can't
see
beyond
12
feet due to
the
fast-falling snow.
So
now
you need to
know
(in
advance)
what
the
angle
will
be when
you're
standing
12
feet
away from a
28-foot tree.
Then
all you'll
have
to do
is
find a tree
that gives you
that angle
reading on
your
surveyor's
transit (or
simple
protractor)
when you're
standing
12
feet away.
Remember
our
formula,
H=D*TAN(A).
Well, in
this case,
we
know
H(Height)
and
D(Distance).
What we're
seeking
is a
certain
angle
such that
H/D=TAN(A).
In short,
we
want
to
find
"the
angle whose
tangent is
equal to II
divided by D".
In trig-
onometry,
that's
known as
the
Arctangent
of A.
Don't worry
we've got
a
subroutine
for that
one, too.
:i':
;'-•"-::
Why do
we add
.5
before
using
INT? Well,
suppose
¥*D»27.&
Siinply
UluHgMT(27.6)
would
give us
an
-answer
of
27
eveii
though
the
unrounded
answer was
closer to 28. By
adding
.5,
we ensure
that
the auns bet
is
rounded
properly.
Try it for a
few
other
numbers just
to
make &ir*
it
works
(e.g., 27.4,
14.8, 14:2),
The
tecfc$<jue is
very
-use-
ful
throughout
progrsmming
*-
whenever
yoa
:
ded number^
EXERCISE
25-1
: Write a
program
which
accepts
inputs for
the height
of
the
tree
and
your
distance
from
the
tree,
and
computes
what the
angle
should
be. Use
the
Arctangent
Sub-
routine
on
page 219 of Appendix A.
162

Other manuals for Radio Shack TRS-80

Related product manuals