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 Co...

Assessment: Computer Science 0478 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science - 0478

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]

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning