2210/21/M/J/24 question 4: worked solution (May/June 2024, paper 21)
Show as plain textHide plain text
Cambridge O Level Computer Science 2210 · 7.8 Identifying and correcting errors in algorithms Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 7 of 8. Q72 2210/21/M/J/24 original Q4 Structured · 10 marks 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 IDEA Check 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 VIDEO ▶ Whole paper Video solution of the whole paper · by ZAINEMATICS. Tap the picture to open it on YouTube.