2210/21/M/J/20 question 4: worked solution (May/June 2020, paper 21)
Show as plain textHide plain text
Cambridge O Level Computer Science 2210 · 7.9 Writing and amending algorithms Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 8 of 8. Q82 2210/21/M/J/20 original Q4 Structured · 8 marks 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 IDEA A loop only ends if its counter can reach the value being tested; check the input before storing it. TOTAL 8 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Mr Bulmer's Learning Zone. Tap the picture to open it on YouTube.