2210/22/M/J/24 question 6: worked solution (May/June 2024, paper 22)
Show as plain textHide plain text
Cambridge O Level Computer Science 2210 · 7.4 Standard methods of solution Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 3 of 8. Q15 2210/22/M/J/24 original Q6 Structured · 8 marks Worked solution (a) Set a total to zero, then keep adding each input until 9999.9 is input. Do not add 9999.9. Total ← 0 INPUT Value WHILE Value <> 9999.9 DO Total ← Total + Value INPUT Value ENDWHILE OUTPUT Total Current value added to Total [1] Total set to 0 before the loop [1] A loop that stops when the value is 9999.9 [1] More than one number input (an INPUT inside the loop) [1] Outputting the total after the loop also earns a mark, but only three of these four points count. A REPEAT ... UNTIL Value = 9999.9 loop is also accepted. (b) Use a counter that starts at 0 and add 1 only when the value is more than 100. Counter ← 0 INPUT Value WHILE Value <> 9999.9 DO IF Value > 100 THEN Counter ← Counter + 1 ENDIF INPUT Value ENDWHILE OUTPUT Counter Counter increased by 1 [1] Selection that tests if the value is greater than 100 [1] Counter set to 0 before the loop [1] A loop that stops when the value is 9999.9 [1] More than one number input, or outputting the counter after the loop, also earn a mark, but only two of these four points count. KEY IDEA Totalling and counting both set a variable to 0 before the loop, update it inside the loop and output it after the loop. TOTAL 8 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by Craig'n'Dave. Tap the picture to open it on YouTube.