STOREing the data pointer to the beginning of the data list. Add line 50
to the previous program:
50 GOTO 10
You will still get the OUT OF DATAerror because as the program
branches back to line 10 to reread the data, the data pointer indicates
all the data has been used. Now, add:
45 RESTORE
and RUN the program again. The data pointer has been RESTOREdand
the data can be READcontinuously.
AVERAGES
The following program illustrates a practical use of READand DATA,
by reading in a set of numbers and calculating their average.
5 T = 0
1"-1 F~EAD ....
20 IF::"; = '-1
25 CT = CT +
::::0 T = T + >::
40 GOTO 10
5~~1PR r HT "THERE \>JEF.:E ".: CT.:" ' ALUE:::;
6~) PRItH "TOTAL = ".:T
70 PI': I tH "A'./EPfiCiE =".: T,,"CT
80 DATA 75, 80, 62, 91, 87, 93, 78, -1
CT
THEH 50: REM CHECK FOR FLAG
1
: REM UPDATE TOTAL
F.:EAD"
RUH
THERE WERE 7 VALUES READ
TOTAL
= 566
AVERAGE
= 80.8571429
Line 5 sets CT,the CounTer,and T, Total,equal to zero. Line10 READs
a value and assigns the value to X. Line 20 checks to see if the value is
our flag (here a -1). If the value READis part of the valid DATA,CT is
incremented by 1 and X is added to the total.
When the flag is READ,the program branches to line 50 which PRINTs
94