EasyManua.ls Logo

Texas Instruments TI-99/4A - Page 180

Texas Instruments TI-99/4A
204 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...
Codebreaker
Codebreaker
is a
game
in which
the
computer
generates
a four-digit
code
number.
and
you
try
to
gllPss
it
7f'rns
;:lrp
not ;:lllowed.
and
no
two digits
may
be
the
same.
Even
with
these
restrictions,
there
are
3024
possible codes,
making
slim
your
chances
of
guessing
the
number
on
the first try. Your gl1Ps"-.
is
:l1Itnmatically
scored
by
the
computer.
Your
score
for each
guess
is displayed in the form "N.R,"
where
N is the
number
of
digits
in
your trial
number
that
appear
in
the
secret
nllmhpr
and
are
positioned
correctly
and
R
is
the
num.ber
of digits in your guess which
although
correct.
are
improperly
placed.
For
example, if
the
number
generated
by
the
computer
is
R2f11
;:lnrl
you guess
6285,
you receive a
sCore
of
1.2.
This
indicates
that
one
number
you
guessed
is
in
the
right
place
(the
2)
and
that
two of your
other
numbers
(8
and
6)
are
present
in
the
secret
number,
but
not in
the
right place. A
score
of
4.0
indicates
that
your guess is
correct.
The
RANDOMIZE
statement
ensures
that
a different
number
will
be
generated
each
time
the
program
is run. After
the
screen
is
cleared, the
computer
generates
the four-digit
number.
Note
that
each digit is
stored
separately
in the array. N.
TheHoop
beginning
at line
160
ensures
that
no two digits
in
the
number
generated
are
the
same.
The
number
of tries is
set
to zero for
each
new
four-digit
number
generated.
The
INPUT
statement
stops
the
program
and
waits
for
you
to
enter
your guess. Be
sure
to
enter
a four-digit
integer
number.
Each
time
you
guess a
number,
the
score
is
set
to zero.
and
the
number
of
tries
is
increased
by
one.
Line
250
takes
the
last
digit from the guess
so
that
it
may
be
compared
against
the
code
number.
If
the digit
matches
the
code
number
in
the
same
position,
then
the
score
is
increased
by 1.
If
not, then the L-Ioop is
used
to
compare
the digit
against
the
other
positions in
the
code
number.
If
it
matches
any
other
position
in
the
code
number.
then
.1
is
added
to the score. Line
340
eliminates
the
last digit from the guess. so
that
the next digit
can
be
taken
for the
comparison.
When
all four digits have been
compared.
thf':
progr:lrn
continues
at
line
360.
IIIĀ·24
Examples:
>NEW
>100
REM
CODEBREAKER
GAME
>110
RANDOMIZE
>120
CALL
CLEAR
>130
FOR
1=1
TO
4
>140
N(I)=lNT(9*RND)+1
>150 IF 1=1
THEN
190
>160
FOR
J=1
TO
1-1
>170
IF
NU)=N(J)
THEN
140
>180
NEXT
J
>190
NEXT
I
>200 TRIE5=0
>-210
INPUT
"ENTER
GUESS,
";GU
E55
>220
SCORE=O
>230
TRIES=TRIES+1
>240
FOR
K=4
TO
1
STEP
-1
>250 DIGIT=(GUESS/10-INT(GUES
5/10))*10
>260 IF DIGIT<>N(K)
THEN
290
>270
SCORE=5CORE+1
>280
GOTO
340
>-290
FOR
L-1
TO
~
>300 IF
N(L)<>DIGIT
THEN
330
>310 SCORE=SCORE+.1
>320
GOTO
340
>-330
NEXT
L
>340 GUESS=lNT(GUESS/10)
>350
NEXT
K
User's Reference Guide

Other manuals for Texas Instruments TI-99/4A

Related product manuals