Lesson #11 Average Sales - Radio Shack TRS-80 Model 100 Basic Manual

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

Advertisement

Lesson #11 Average Sales
In this lesson you will learn how to compute the average daily sales using the data you
stored in RAM in the last Lesson under the name SALEDA.DO.
Arrays with two dimensions will be used so that the data can be examined on a daily
or weekly basis. You will learn how to sort an array so that the median can be
calculated. Subroutines will be used to avoid repetitive blocks of code in your
programs. The TAB statement will be used to space the output neatly.
Experiment #1 Display the File
The following program will read 6 weeks of daily sales values from file SALEDA.DO
in RAM and display the values.
Clear working memory and enter the following program:
5
OPEN "RAM:SALEDA.DO" FOR INPUT AS 1
10
FOR W = 1 TO 8
:
FOR D = 1 TO 5
20
INPUT
#
1 t S<WtD)
30
NEXT D
.
NEXT W
.
1I0
PRINT "WEEK
MON
TUE
WED
THU
FRI"
50
FOR W = 1 TO 8
PRINT W;
80
FOR D=1 TO 5
70
PRINT TA6(D*5) S<WtD);
80
NEXT D : PRINT
80
NEXT W
Execute this program.
The program will read the file SALEDA.DO containing sales data.
The following table will then be output to the LCD:
WEEK
MON
TUE
WED
THU
FRI
1
280
275
3£18
280
250
2
300
280
320
300
242
3
282
270
350
310
255
4
310
250
310
280
280
5
280
280
280
280
270
8
285
280
330
275
258
Line 5 The OPEN statement opens the RAM data file "SALEDA.DO" for input and
assigns the file number I to it.
Line
H~
The first FOR statement,
FOR W = 1 TO 8
sets up an outer loop to index through the six weeks. The second FOR statement
FOR D = 1 TO 5
sets up an inner loop to index through the five days of the week.
131

Advertisement

Table of Contents
loading

Table of Contents