•
•
0,11<1
Types,
Variables
and
Identifiers
Example 2
In
problems which need
to
simulate the dealing of cards
you
can make cards correspond
to
the numbers 1
to
52
as
follows:
1 to
13
ke,
two king of hearts
14
to
26
ke,
two king of clubs
27 to 39
ke,
two king of diamonds
40 to 52
ke,
two king of spades
A particular card can be Identified
as
follows:
100
REM
Card
identification
110
LET
card
=
23
120
LET
suit
=
(card-1)
DIV
13
130
LET
vaLue
=
card
MOD
13
140
IF
vaLue
=0
THEN
LET
vaLue
=13
150
IF
vaLue
=1
THEN
PRINT
"Ace
of
";
160
IF
vaLue
>=
2
AND
vaLue
<=
10
THEN
PRINT
vaLue
I
"of
";
170
IF
vaLue
=
11
THEN
PRINT
"Jack
of
";
180
IF
value
=12
THEN
PRINT
"Queen
of
";
190
IF
value
= 13
THEN
PRINT
"King
of
";
200
IF
suit
= 0
THEN
PRINT
"hearts"
210
IF
suit
= 1
THEN
PRINT
"clubs"
220
IF
suit
= 2
THEN
PRINT
"diamonds"
230
IF
suit
=3
THEN
PRINT
"spades"
There are new ideas
In
this program. They are
In
line
160.
The meaning
is
clearly that
the number
is
actually printed only if two logical statements are
true.
These are:
value
is
greater than or equal
to
2 AND value
is
less than or equal
to
10
Cards outside this range are either aces or court cards' and must be treated differently.
Note also the use of
!
in
the PRINT statement
to
provide a space
and;
to
ensure that
output continues on the same
line.
There
are
two groups
of
mathematical functions which
we
have not discussed
here.
They
are the trigonometric and logarithmic.
You
may need the former
In
organising screen
displays.
Types
of functions are also fully defined
in
the reference section.
LOGICAL
VARIABLES
Stnctly speaking, SuperBASIC does not allow logical variables but
it
allows you
to
use
other vanables
as
logical ones. For example you can run the following program:
100
REMark
Logical
VariabLe
110
LET
hungry
= 1
120
IF
hungry
THEN
PRINT
"Have
a
bun"
You
expect a logical expression
in
line
120
but the numeric variable, hungry,
is
there •
on
its
own. The system Interprets the value,
1,
of hungry
as
true and the output
is:
Have
a
bun
If
line
110
read:
LET hungry
= 0
there would be no output. The system Interprets zero
as
false and
all
other values as
true. That
is
useful but you can disguise the numeric quality ot hungry by writing:
100
REMark
LogicaL
VariabLe
110
LET
true
= 1 :
faLse
= 0
120
LET
hung
ry
=
true
130
IF
hungry
THEN
PRINT
"Have
a
bun"
STRING
VARIABLES
There
is
much
to
be said about handling stnngs and string variables and this
is
left
to
a separate chapter.
•
'52
12f84