AMSTRAD CPC464 User Manual page 99

Cpc464 colour personal computer 64k
Hide thumbs Also See for CPC464:
Table of Contents

Advertisement

An example program is:
1 0 R E A D X , Y , Z
2 0 P R I N T X ; " + " ; Y ; " + " ; Z ; " = " ; X + Y + Z
3 0 D A T A 1 , 3 , 5
The data can be either numerical or text or a mixture of both. Don' t worry if all your data doesn' t fit
onto one line you just start a new line with the DATA command at the beginning. When the
computer comes across a READ command it searches through the program for the next sequential
piece of data regardless of where it may occur. Make sure you have sufficient data for all your
READ s or an error will result.
The only way to interrupt this sequential input of data is to use the R E S T O R E command. This sets
the data pointer to the beginning of the program again allowing the same data to be read several
times if required. This program illustrates the use of the D A T A , R E A D and R E S T O R E commands:
1 0 F O R C = 1 T O 5
2 0 READ X$
3 0 P R I N T X $ ; " " ;
4 0 NEXT C
5 0 R E S T O R E
6 0 G O T O 1 0
7 0 D A T A H E L L O , H O W , A R E , Y O U , T O D A Y
[ESC] to break from this program.
Press
Note that although the data line has been placed at the end of the program in the example, it can be
located anywhere that is convenient.
The DATA command need not be used just to contain information which is to be PRINTed when
read; numeric values in a DATA statement can, for example, be read into a SOUND command. Type
in:
1 0 F O R n = 1 T O 3 0
2 0 R E A D s
3 0 S O U N D 1 , s , 4 0 , 5
4 0 N E X T n
5 0 D A T A 1 0 0 , 9 0 , 1 0 0 , 1 1 0 , 1 2 0 , 1 1 0 , 1 0 0 , 0
6 0 D A T A 1 3 0 , 1 2 0 , 1 1 0 , 0 , 1 2 0 , 1 1 0 , 1 0 0 , 0
7 0 D A T A 1 0 0 , 9 0 , 1 0 0 , 1 1 0 , 1 2 0 , 1 1 0 , 1 0 0 , 0
8 0 D A T A 1 3 0 , 0 , 1 0 0 , 0 , 1 2 0 , 1 5 0
If you cannot hear anything, adjust the volume control at the right hand end of the computer.
Concluding this brief introduction to BASIC, here' s a program that enables you to play pontoon with
the CPC464 (blackjack and 21 are the other well known names for variations). It demonstrates the
use of many features of BASIC, and should be readily understood thanks to the use of renresentative
variable names. You can embellish it with graphics, add tension with sound - and generally develop
the theme in the way that all the best BASIC programs evolve from a humble core.
The object of the game is get as close to a total of 21 by adding the face values of the cards in your
hand, and then for the house to attempt to match this, or get closer still - without exceeding 21 and
so going ' bust' . After typing in line 1, use the command AUTO to automatically generate the line
numbers..
1 R E M P O N T O O N
1 0 R E M I N I T I A L I S E
2 0 Y C = 2 : C C = 2
3 0 ACES=0
4 0 C A C E S = 0
50 S=0
60 T=0
7 0 D I M S U I T $ ( 4 )

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents