Analysis
:
Line
10
sets
the value of Y equal to
1.
Line
20
sets
the value
of
N equal to
0.
These
two
values
can be quickly and easily check-
ed by
typing
PR I NT Y , N
in the
calculator
mode.
Line
30
inputs
the
answer to the question as either Y or N, (it will also
accept YES
or
NO and any other words starting with Y and N). "A"
takes
on the value of Y or N as
defined in lines
10
and
20,
Line
40
tests the value
of
A,
and if
it is
1
, sends control to line
60.
If
it is
not 1 (but not
necessarily
0),
the line
40
test defaults and falls
through
to
line
50.
The appropriate
message
is
printed.
Line
59
is a
protective END
so
if
line
50
_is printed, line
60
will
not
also
be printed.
More
Analysis:
We have carefully
given
Y
and N
values
of 1 and
0.
This
does not
mean that other
letters
might
not
have
those same values.
That does not
matter
as long
as
only Y and
N are hit.
The present program relies
on line
40
defaulting
to the next line
if a 1
is
NOT
found.
As
a partial precaution
against
a user hitting the
wrong letter
accidentally
and coming up
with
the
wrong answer,
we can "backstop" our
program with these
additional
lines:
45 IF
A
=
THEN 50
47
PRINT
"PLEASE
ANSWER WITH
EITHER A Y OR N!"
49
END
Analysis
:
Line 45 insists that to get the response
to line
50,
zero
must be entered. We
know that
an N
will
do that for
sure. Other
letters might also have the value
of zero.
Line 47 gives the "default" answer,
cautioning
the
operator that he gave other
than
a
YES or
NO.
Line 49 protects against printing
the default answer
and
running into the line
50
answer.
EXERCISE
16-2:
Design and write
a
simple program
that asks the user at least 5
questions,
and in the process carries
on
a
little conversation with
him.
I
You're on
your
own with this one.
Try a
PRINT
A^CjrjjE^GsletcJ
routine to
s#e .
IE*»jf- crtfeer
letter
variable is
storing
£ vafufc ot i or 0.
91