Cambridge O Level Computer Science 2210 · 7.9 Writing and amending algorithms

Q82 · 2210/21/M/J/20 Q4

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

Q822210/21/M/J/20original Q4Structured · 8 marks
Question 4 from 2210/21/M/J/20

Worked solution

(a)

Count starts at 0 and goes up by 1 each time round the loop. [1]

The test is made after it has gone up, so Count can never be 0 at the end of the loop. The condition UNTIL Count = 0 is never true, so the loop never ends. [1]

(b)

Use a separate variable for the input, store it only if it is 100 or more, and stop after 50 numbers.

Count ← 0
REPEAT
    INPUT Number
    IF Number >= 100
      THEN
        Values[Count] ← Number
    ENDIF
    Count ← Count + 1
UNTIL Count = 50

A separate INPUT statement for the number (not into the array) [1]

An IF statement is attempted [1]

The IF statement is completely correct (Number >= 100 and the store inside it) [1]

The loop ending changed to UNTIL Count = 50 [1]

(c)

Change the IF statement (or add a second IF) so the number is also tested to be less than or equal to 200 [1]

The number is then stored only when both tests are true, for example Number >= 100 AND Number <= 200. [1]

KEY IDEAA loop only ends if its counter can reach the value being tested; check the input before storing it.
TOTAL 8 marks

Official mark scheme

Mark scheme for 2210/21/M/J/20 question 4
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.