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

Q72 · 2210/21/M/J/24 Q4

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

Q722210/21/M/J/24original Q4Structured · 10 marks
Question 4 from 2210/21/M/J/24

Worked solution

(a)

Check each line:

Line 01: Loop is a counter, so DECLARE Loop : INTEGER [1]

Line 07: IF used instead of a loop, so write FOR Loop ← 1 TO Limit [1]

Line 09: the number must go into Value, so INPUT Value [1]

Line 10: values should be added, so Total ← Total + Value [1]

(b)

Use ROUND with the value and the number of decimal places:

OUTPUT "The average of the numbers entered is ", ROUND(Total / Limit, 1)

ROUND used with two values separated by a comma [1]

Correct values: Total / Limit and 1 [1]

(c)

Check the value straight after it is input, and ask again if it is wrong:

After line 09 (the input), add a WHILE loop (pre-condition loop) [1]

It checks that the value is between 1 and 500 inclusive [1]

If the value is outside the range, output an error message [1]

and input the value again inside the loop [1]

A REPEAT loop also scores: start it before the input message and end it with UNTIL the value is from 1 to 500.

KEY IDEACheck the type and the operation on each line, and validate input with a loop that repeats until the value is allowed.
TOTAL 10 marks

Official mark scheme

Mark scheme for 2210/21/M/J/24 question 4
VIDEO
▶ Whole paper

Video solution of the whole paper · by ZAINEMATICS. 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.