Commodore 2001-8 User Manual page 54

Table of Contents

Advertisement

A3, A4, A5, etc. This is acceptable but would require a lot of parallel logic to accomplish the summation
10 INPUT "ACCOUNT, CHARGE"; I, C
20IFI=1THENA1=A1+C
30 IF 1=2THEN A2=A2+C
etc.
This list can be stored in a single variable which is actually a list of variables. This list is an array of
values and an individual value is accessed by an index. The index we can use is the account number. Our
program can be reduced to:
10 INPUT "account, charge"; I,C
20 A(I) = A(I) + C
30 GOTO 10
The list we have represented has 9 rows and 1 column. Thus it is a 1 dimensional array. A multiple column
table can also be represented. This is a two dimensional array.
Account #
Balance
#oftransactions
1
$100
1
2
$135
1
3
$57.86"
1
4
<$987>
1
5
$22
1
6
<$63>
1
7
$50
1
8
<$21>
1
9
$21
1
Our table has 9 rows and 2 columns. To access a certain entry position, you must specify the row index
and column index of where it is contained. For example, the quantity denoted by a
*
is in row 3, column 1.
In order to use such a table in a BASIC program, you must provide a statement, to describe the number of
rows and columns contained in the array variable.
Such a description is a DIMension statement. For our table of 9 rows and 2 columns we could write
DIM A(9,2)
Let us rewrite our program to update the column containing the number of transactions
10 INPUT "ACCOUNT, CHARGE"; I, C
20 A(I,1)=A(I,1)+C
30 All ,2) = All ,2)
+
1
40 GOTO 10
Now suppose that we had a table for each of 5 companies and each company had 9 accounts and each
account had a balance and each balance had a number of transactions. We can describe this as piling
sheets of paper on top of each other and refering to each sheet by number.
50

Advertisement

Table of Contents
loading

This manual is also suitable for:

Pet 2001-8

Table of Contents