Since the days to be printed are below average, use the <
operator.
Here is the last loop in the program:
' Print the number of each day with BELOW average rainfall PRINT "Below average days: " FOR COUNT = 1 TO NUM IF ( RAIN( COUNT ) < AVERAGE ) THEN PRINT COUNT END IF NEXT COUNT END
This program would be hard to write without using an array. By using an array the program works for any number of days. Also, keeping the data in the array allows it to be used several times (first for computing the average, next for finding the below average days). This type of multiple-use is very common.
Here is a sample run of this new version of the program:
How many days to average? ? 5 Input rain for day number 1 ? 0.0 Input rain for day number 2 ? 5.5 Input rain for day number 3 ? 1.2 Input rain for day number 4 ? 4.8 Input rain for day number 5 ? 0.3 The average rainfall is: 2.36 Below average days: 1 3 5 Press any key to continue
Would it be hard to add to the program so that it next writes out the days with ABOVE average rainfall?