Question 1
1 markThe algorithm below gets whole numbers entered by the user.
count ← 0
num ← USERINPUT
WHILE num ≠ 0
IF num < 0 THEN
count ← count + 1
ENDIF
num ← USERINPUT
ENDWHILE
OUTPUT countState the purpose of the algorithm.
Model answer
It counts how many negative numbers the user enters before entering 0, and outputs that count.
Explanation
count only goes up when num < 0, and the loop stops when 0 is entered, so the final output is the number of negative values entered. For example, 4, -2, 7, -9, -1 and then 0 outputs 3. Saying 'it counts the numbers' is not enough because positive numbers are not counted.
Mark scheme
-
1 mark
To count (and output) how many negative numbers are entered (before 0 is entered)
Mark is for AO2 (apply). A. how many numbers less than 0 are entered. NE. counts the numbers entered. R. outputs the negative numbers.