Question 1 Report
A program uses a sentinel value to control input into an array.
DECLARE Numbers : ARRAY[1:20] OF INTEGER
DECLARE Count : INTEGER
DECLARE Value : INTEGER
Count <- 0
OUTPUT "Enter numbers (-1 to stop):"
INPUT Value
WHILE Value <> -1 AND Count < 20
Count <- Count + 1
Numbers[Count] <- Value
INPUT Value
ENDWHILE
OUTPUT Count, " numbers entered"
(a) State what a sentinel value is, using this example. [2]
(b) If the user enters: 15, 8, 42, 3, -1, state the contents of the array and the value of Count. [2]
(c) Explain the purpose of the condition Count < 20 in the WHILE loop. [2]
(d) Write pseudocode to extend the program so it also calculates and outputs the average of the numbers entered (after the loop). [2]
(e) State one advantage of using a sentinel value compared to asking the user in advance how many numbers they want to enter. [1]
Everything you need to excel in your exams