Computer Science · May / June 2026 · Paper 21 · Question 7
0478
As printed in the paper
The question as text
An algorithm has been written in pseudocode for a user to repeatedly input positive whole numbers and store them in an array called £¤¦ until –1 is input or until the array is full. The algorithm outputs the average of the numbers to 2 decimal places. ¥ }»§{ »¨ ¼ ~|· ¥´ }»§{ ¨ ¼ ~|· ¥ }»§{ {½ ¼ ~|· ¥ }»§{ £ ¼ {{¾¤¼¥¥¦ ¬ ~|· ¥ »¨ ¥ ¨ ¥ ¥ © ¿©£ ¨ £À¨À½ « ¿ ¥ ~|© | ¥ Á°~§ | w {|} »¨ vw ¥¥ } ¥ £¤»¨¦ | ¨ ¨ x ´ »¨ »¨ x ~|© | |}Á°~§ »¨ »¨ {½ »¨ t ¨ © ¿ ½ À£ ¿Â |}Ã{½Â ´Ä Identify the line numbers of four errors in the pseudocode and suggest a correction for each error. error 1 line number correction error 2 line number correction error 3 line number correction error 4 line number correction [4]
Read automatically from the paper; the printed page above is exact.
Show the answer and mark scheme
One mark for each line identified and correction given.
Line 3 – should be DECLARE Average : REAL
Line 9 – should be WHILE Number <> -1 AND Counter <= 100 DO
Line 11 – should be Total ← Total + Number // Total ← Total + Values[Counter] Line 16 – should be Average ← Total/Counter
01 DECLARE Counter : INTEGER
02 DECLARE Total : INTEGER
03 DECLARE Average : REAL
04 DECLARE Values : ARRAY[1:100] OF INTEGER
05 Counter ← 1
06 Total ← 0
07 OUTPUT "Please enter a positive whole number or -1 "
08 INPUT Number
09 WHILE Number <> -1 AND Counter <= 100 DO
10 Values[Counter] ← Number
11 Total ← Total + Number // Values[Counter]
12 Counter ← Counter + 1
13 INPUT Number
14 ENDWHILE
15 Counter ← Counter - 1
16 Average ← Total / Counter
17 OUTPUT "The average is ", Round(Average, 2)
Make a free account to save your answers and see your weak topics and ask the AI why a wrong answer is wrong.

