Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 7 of 8.
Read the code line by line and compare it with what the algorithm should do. Write four of these:
Line 02: ROUND(..., 1) gives a decimal. Correction: N ← ROUND(RANDOM() * 99, 0) + 1 [1]
Line 12: the message says lower again. Correction: OUTPUT "The number is higher than your guess" [1]
Line 14: Counter is inside the ELSE part, so it is only added to when the guess is not too high (and is missed when the guess is too high). Correction: move Counter ← Counter + 1 to after ENDIF (line 15), before UNTIL G = N [1]
Line 17: Guess is never used. Correction: OUTPUT "Well done, you took ", Counter, " attempts" [1]
Give a method and an example of it:
Method: use meaningful identifier names [1]
Example: rename N to Number (or G to Guess). [1]
Other methods that score: comments (for example // loops until the guess equals the number) or writing the algorithm as a procedure or function.
▶ 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.