Design pseudocode to count ten integer scores in these bands: below 40; 40 to 69 inclusive; 70 or above. Use scores[0] through scores[9] and output all three counts.
Check your counts for scores = [0, 39, 40, 69, 70, 100, 38, 41, 68, 71].
Answer
Pseudocode (zero-based list):
low = 0
mid = 0
high = 0
for i = 0 to 9
if scores[i] < 40 then
low = low + 1
elseif scores[i] < 70 then
mid = mid + 1
else
high = high + 1
endif
next i
print low, mid, high
The branches are exclusive; 40 and 69 belong to mid and 70 to high.
For the printed scores the band counts are 3 below 40, 4 in 40..69 and 3 at least 70.
The band partition assumes integer scores; the original does not specify the behaviour for a fractional score between 69 and 70.
Mark scheme
| B1 | Initialise all three counts to zero |
| B1 | Visit all ten scores exactly once |
| B1 | Increment low only for scores below 40 |
| B1 | Increment mid only for 40 through 69 |
| B1 | Increment high only for 70 or above |
| B1 | Output all three final counts after the loop |