Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 3 of 8.
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 TotalCurrent 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.
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 CounterCounter 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.
▶ Topic lesson
A lesson on this topic · by Craig'n'Dave. 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.