50
FOR
W
=
1
TO
8
PRINT
W;
55
WA
=
0
80
FOR
0
= 1
TO
5
85
WA
=
WA
+
S(W.O)
70
PR
I
N.T
TAB(O
*
5)
S(W,O)
;
80
NEXT
0 : PRINT
WA
I 5
90
NEXT
W
Execute the program.
Here
is
what the output should look like:
WEEK
MON
TUE
WED
THU
FRI
AVG
1
280 275
346
280
250
286.2
2
300
260
320
300
242
284.4
3
292
270
350 310
255
295.4
4
310
250
310
290 280 284
5
280 280
290
280
270
280
8
285
290
330
275 258
287.8
An
additional column containing the weekly averages has been printed.
The average (or mean) was calculated by adding up the five values for the week and
dividing the sum by five. Line
65
calculates the weekly sum and stores it
in
the
numeric variable W
A. The variable WA
is
initialized to zero outside the loop (lines 60
- 80) where the sum
is
computed. The weekly sum is divided by five to obtain the
average and displayed
in
line 80.
Experiment
#3
Computing the Average
for Each Weekday
The previous program will be changed so that the average sales for each weekday can
be calculated. There are six sales figures for each
day,-
so to calculate the average,
these six values must be added and the sum divided
by
six. This must be done for
each of the five days.
Add
the following lines to the program:
95
PRINT
"AVG";
100
FOR
0=1
TO
5 : OA=0 :
~OR
W=l
TO
8
110
OA
=
OA
+
S(W.O)
:
NEXT
W
120
PRINT
TAB(0*5)
INT(OA/6);
130
NEXT
0
List the program to confirm it
is:
5
OPEN
"RAM:SALEOA.OO"
FOR
INPUT
AS
1
10
FOR
W
'"
1
TO
8
.
FOR
0
'"
1
TO
5
.
20
INPUT •
1 •
S(W,O)
30
NEXT
0
.
NEXT
W.
40
PRINT"WEEK
MON
TUE
WED
THU
FRI
AIJG"
50
FOR
W
= 1
TO
6
PRINT
Wi
55
WA
;;
0
60
FOR
0
;;
1
TO
5
134