Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 8 of 8.
Fill in each empty box using what the question says. The algorithm inputs a value, rejects it if it is out of range (and inputs again), otherwise adds it to the total and counts it. It stops when 50 values are accepted.
Top parallelogram: INPUT Value [1]
First decision (Yes goes back to the input, No continues left): IS Value <= -20 OR Value >= 50 ? [1]
Left process box (No branch): Total ← Total + Value [1]
Second process box: Count ← Count + 1 [1]
Second decision (Yes continues down, No goes back to the input): IS Count = 50 ? [1]
The two output parallelograms: OUTPUT Total and then OUTPUT Total / 50 [1]
To keep every value, use an array and a second loop:
Change INPUT Value so that each accepted value is saved into an array, for example Numbers[Count] ← Value [1]
... using the counter as the index [1]
After the first loop (outside it), add a second loop that repeats 50 times [1]
Inside the second loop add an OUTPUT that outputs the array content at the counter position, for example OUTPUT Numbers[Count] [1]
▶ Topic lesson
A lesson on this topic · by Mr Bulmer's Learning Zone. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.