66
CHAPTER
4 Programming
with
BASIC
Language
• Using Arrays with the
DIM
Mode
In this example, we will process two types
of
data
by
using two-dimensional
array variables.
Example:
Store the names and heights
of
15
people.
P0
10
DIM A$(
1,
14)
20
FOR
C=0
TO
14
30
INPUT
"NAME'',
A$
( 0
'c
)
40
INPUT
"HEIGHT''
,A$(
1
,C)
50
NEXT
C
60
END
p 1
10
INPUT
"NAME'',
N$
20
FOR
C=0
TO
1 4
30
IF
N$=A$(0,C>
THEN
PRINT
A$(1,C>;"cm~:GOTO
10
40
NEXT
c
50
PRINT
''NO
NAME''
60
GOTO
10
Input the names and heights to
PO
since this
is
the input program.
Pl
is
the
program to display the height
of
the pertinent person when a name
is
entered.
Variable C
is
used for controlling the
FOR~
NEXT loop and variable
N$
is
used
for temporary storage when searching a name.
Array
A$
(0, 0)
~A$
(0, 14)
is
an array variable to store the names
of
15
people
and array
A$
(1, 0)
~
A$
(1, 14)
is
an array variable to store the heights
of
15
people.
*On line 30 in
Pl,
when the name
of
the input person
is
concerned, his height
is
displayed. Then execution
is
jumped
to
line 10. To input a different name,
press
the§!
key when the height
of
previous person
is
displayed.