Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 2 of 3.
Tick goes up by 1000 every second. Work out the Tick values for the warning time and the end time, then wait for each one with a loop.
PROCEDURE Timer(Mins, Secs : INTEGER)
DECLARE WarningTick, EndTick : INTEGER
EndTick ← Tick + 1000 * ((Mins * 60) + Secs)
WarningTick ← EndTick - (30 * 1000)
REPEAT
//do nothing
UNTIL Tick = WarningTick
OUTPUT "30 seconds to go"
REPEAT
//do nothing
UNTIL Tick = EndTick
OUTPUT "The time is up!"
ENDPROCEDUREProcedure heading with the two parameters, and ENDPROCEDURE [1]
Attempt to work out the total time / EndTick / WarningTick from Tick [1]
Correct calculation of both EndTick and WarningTick (minutes × 60 + seconds, × 1000, 30 seconds earlier for the warning) [1]
A sensible design: two separate loops (warning time, then end time), or one loop with an IF for the warning [1]
The loop design is completely correct (warning message comes first, only once, then the final message) [1]
Both messages output: "30 seconds to go" and "The time is up!" [1]
▶ Whole paper
Video solution of the whole paper · by Papersdock. 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.