EasyManua.ls Logo

AMSTRAD CPC464 - 4.12 DATA

AMSTRAD CPC464
249 pages
Print Icon
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...
We can now write the framework for a subroutine to deal a card:
10 DIM PACK(52)
20 FOR X = 1 TO 52
30 LET PACK(X)=0
40 NEXT X
. . . . . . . . . . . .
1000 CARD=INT(RND*52)+1
1010 IF PACK(CARD) = 1 THEN GOTO 1000
1020 PACK(CARD) = 1
1030 RETURN
Note that the DIM statement is the first line in the program . This is because an array can only be
dimensioned once - it cannot be redimensioned further on in the program.
Lines 20 to 40 set the elements of the array to zero. The subroutine that starts at line 1000 then
chooses a card at random and checks that it has not been already dealt. If it has, then another is
chosen until one is found that is still in the deck . The routine then changes the value of the
appropriate element in the array to signify that the card has now been dealt and returns from the
subroutine.
Array handling is not restricted to single dimensions but can be extended to any number of
dimensions desired. This is achieved by simply adding further reference numbers to the variable. For
example a 10x10x10 array (or matrix) can be set up by the command:
DIM ARRAY(10,10,10)
This technique is useful for dividing data into smaller subsets within a large group.
In our example we could split the pack into four suits of thirteen cards which can then be accessed
separately by using the format:
DIM PACK (4,13)
Now if we wish to find the four of clubs,which might have been element 43 in our original array, we
simply have to examine element (2,4) - assuming that clubs are the second row in our new array.
Arrays do not have to be used to store numerical data but can be used to handle strings as well . An
application for this might be to record the names of people booked into seats at a theatre or on an
aeroplane flight.
4.12 DATA
This command, in conjunction with the command READ, can be used to input data into a program.
The required data is listed in a line with each item separated by a comma and the whole list
preceeded by the DATA command. The data can now be accessed sequentially using the READ
command.

Table of Contents

Other manuals for AMSTRAD CPC464

Related product manuals