Write an algorithm using pseudocode which takes temperatures input over a 100 day period (once per day) and output the number of days when the temperature was below 20C and the number of days when the temperature was 20C or above.
(NOTE: since the number of inputs is known, a for ... to loop can be used. However, a while loop or a repeat loop would work just as well).
total1 = 0: total2 = 0
for days = 1 to100
input temperature
if temperature < 20 then total1 = total1 + 1
else total2 = total2 + 1
endif
next
print total1, total2
This is a good illustration of an algorithm which could be written using the case construct instead of if ... then ... else. The following section of code replaces the statements if temperature < 20 then ...... endif:
case temperature of
1: total1 = total1 + 1
2: total2 = total2 + 1
Endcase