EasyManua.ls Logo

Radio Shack TRS-80 - Page 104

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...
the
RND(X)
generator.
We have
told
it to
generate
integers between
1
and
2,
and
of
course
that
restricts it
to
just
the
numbers
1
and 2.
Heads is
"1"
and
Tails is
"2".
3
An
ON-GOTO
test
sends
X=l to
line
60
where
the
"Heads" are
counted,
and X=2
to line
70
where
the
"tails"
are
counted.
Note
that
this test
is the
last
statement
in the
multiple
statement
line.
Line
50
is a
default
line.
If
X
=
other
than 1 or
2,
the error
message will be
printed and
execution
will
END. It
will never
happen,
but you
are insisting
on proof.
Line
60
sets up H
as a
counter.
H was
initialized
as
zero in
line
10,
and
each time
the
ON-GOTO
test
sends
control to
this
line
because X=l, H
is
incremented
by one and
keeps
count of
the "Heads".
The
second
statement
sends
control to
line
80
where
only
the first
statement,
NEXT N,
(N.N), is
executed.
When the
N Loop
has gone
through
all "F"
number
of
passes,
control
in line
80
will
move
to
the
4
blank
PRINT(P.)
statements.
Until
then,
the
N.N.
sends
it back to
line
40.
Line
40
generates
another
random
number
(1
or
2).
If
the next
X=2
the
ON-GOTO
sends
control to
line
70.
Line
79
keeps
track of
the
tails, then
passes to
Line
80
and
the NEXT N.
When
the last
"N" is
"used
up", it
inserts 4
blank print
lines and
falls
to
. .
.
Line
90
where the
Headings
are printed,
then the
blank line, then
the values
of
H,T
andF.
Line
100
calculates and
prints
the
percentage of
heads,
and
percentage
of tails,
and
then
prints 3
blank
lines at
the end to
make the
display look
less cluttered.
More
Than One
Generator at
a
Time
It is
possible to
generate more
than one
random
number
by
using
more
than one
generator
in
a
program.
This
has
special
value
when
the ranges
of
the generators
are
different,
but is
helpful even
if their ranges
are the same.
To
make
the point, we
are
going to get
you started
creating a
computer
game of
"Craps"
where 2
dice are
"rolled".
Each
"die"
has six sides,
each side
having
1, 2, 3,
4,
5
or
6
dots,
respectively.
When
the 2 dice are
rolled, the
number of dots
showing on their
top
sides
are
added.
That
sum is
important
to the
game. Obviously,
the lowest
number that can
be rolled
is
2,
and
the
highest
number is
12. We
will
set up a
separate Random
Number
Generator
for each
die, give each a
range from 1
to
6,
and
call
them die "A"
and die "B".
Type
NEW
,
then
the
following:
5
A=RND(6)
:B=RND(6)
:N=A+B
60
P.N
.
.
. RUN
a
few times to
get the idea.
102
It eart
a&obo
dofie
with
a
singe
'gnMt&fe
but
,,.
that
wouldn't
mafee
our
point .v.
would it*

Other manuals for Radio Shack TRS-80

Related product manuals