The array Rain[1:12] has been declared to store the rainfall, in mm, for each month of a year. Look at this pseudocode:
Total ← 0
Wettest ← 1
FOR Month ← 1 TO 12
INPUT Rain[Month]
WHILE Rain[Month] < 0 OR Rain[Month] > 500 DO
OUTPUT "Invalid - enter a value from 0 to 500"
INPUT Rain[Month]
ENDWHILE
Total ← Total + Rain[Month]
IF Rain[Month] > Rain[Wettest]
THEN
Wettest ← Month
ENDIF
NEXT Month
OUTPUT "Total: ", Total
OUTPUT "Average: ", ROUND(Total / 12, 1)
OUTPUT "Wettest month: ", Wettest
Describe the processes involved in this algorithm.
Model answer
For each of the 12 months, the rainfall is input into the array Rain. Each value is validated: while it is below 0 or above 500, an error message is output and the value must be entered again. Each valid value is added to Total, and if it is higher than the rainfall of the wettest month so far, that month's number is stored in Wettest. After the loop, the total, the average rounded to 1 decimal place and the number of the wettest month are output.
Explanation
This one loop combines validation, totalling and finding a maximum. Wettest stores a position rather than a value, so it can be used both to compare (Rain[Wettest]) and to report which month it was.