Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 2 of 3.
Add 1 to the seconds. When the seconds reach 60, reset them and carry into the minutes, then the hours:
PROCEDURE Tick()
SS ← SS + 1
IF SS = 60 THEN
SS ← 0
MM ← MM + 1
IF MM = 60 THEN
MM ← 0
HH ← HH + 1
IF HH = 24 THEN
HH ← 0
CALL NewDay()
ENDIF
ENDIF
CALL CheckAlarm()
ENDIF
ENDPROCEDURESS increased by 1 each call [1]
CheckAlarm() called when SS has just been set to 0 [1]
Test for SS = 60 [1]
SS set to 0 and MM increased by 1 [1]
When MM reaches 60, MM set to 0 and HH increased by 1 [1]
When HH reaches 24, HH set to 0 and NewDay() called [1]
▶ Whole paper
Video solution of the whole paper · by Pseudocode Pro. 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.