Cambridge O Level Computer Science 2210 · 7.8 Identifying and correcting errors in algorithms

Q76 · 2210/21/M/J/25 Q6

Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 7 of 8.

Q762210/21/M/J/25original Q6Structured · 6 marks
Question 6 from 2210/21/M/J/25

Worked solution

(a)

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]

(b)

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.

KEY IDEACompare each line with the stated purpose: wrong values, repeated messages, misplaced statements and unused variables are the usual errors.
TOTAL 6 marks

Official mark scheme

Mark scheme for 2210/21/M/J/25 question 6
VIDEO
▶ 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.