Radio Shack TRS-80 Model 100 Basic Manual page 141

Basic language lab
Hide thumbs Also See for TRS-80 Model 100:
Table of Contents

Advertisement

65
WA = WA + 8(WtO)
70
PRINT TAB(0*5) 8(WtO);
80
NEXT 0
.
PRINT WAf5
.
80
NEXT 14
85
PRINT
II
AI)G" ;
100 FOR 0=1 TO 5
.
OA=0
.
FOR 14=1 TO
6
.
.
110 OA = OA + 5(14.0)
:
NEXT 14
120 PRINT TAB(0*5) INT(OAf6)
j
130 NEXT 0
Execute this program. The output should appear as
WEEK
MON
TUE
WED
THU
FRI
AI)G
1
280
275
3a6
280
250
286.2
2
300
260
320
300
2a2
28a.a
3
282
270
350
310
255
285.a
a
310
250
310
280
260
28a
5
280
280
280
280
270
280
6
285
280
330
275
258
287.8
AVG
281
270
3211
288
255
Lines 5 - 98 The first part of the program remains unchanged.
Line 95 The row label" AVG" is displayed. The semicolon (;) suppresses the
carriage return so the averages will be displayed on the same line.
Line
lee
The first FOR statement
FOR 0=1 TO 5
defines an outer loop which increments through each day. The assignment state.ment
OA=0
initializes the daily sum to zero. The second FOR statement
FOR 14=1 TO 8
defines an inner loop which sums the six week's sales for a given day.
Line 118 The sales for a given day are added and stored in the numeric variable DA.
The NEXT statement defines the end of the inner loop.
Line 128 The daily average is displayed. The TAB function is used to neatly space
the output. The INT function is used to drop any decimal part for neater appearance of
the output. The semicolon (;) suppresses the carriage return so that the next average
will be printed on the same line.
Line 138 The outer loop which increments through each day of the week is
terminated.
By using a two dimensional array S for the sales values, it was very easy to process
the data either weekly (row by row) or daily (column by column). The program could
have been written using a singly dimensioned array and FOR
I
NEXT loops with the
STEP options. However, it was easier to write the program using the two dimension
array.
135

Advertisement

Table of Contents
loading

Table of Contents