Skip to content
MathsGenie logo
Open app

Course home

  1. IGCSE
  2. Computer Science Edexcel
  3. Question bank

Develop code

EasyMediumHard
123456789101112131415161718192021222324
Question 19

There are four errors in the pseudocode in Figure 2 which is designed to count and output the number of low (negative value), normal (zero value), and high (positive value) water level readings.

Write the correct code for line 10.

Figure 2

LineCode
01
02SET levels TO [1, -2, 0, 3, -1, 2, 0]
03
04SET low TO 0
05SET high TO 0
06SET index TO 0
07
08WHILE NOT (index > LENGTH(levels)) DO
09
10IF levels[index] >= 0 THEN
11SET high TO levels[index]
12ELSE
13IF levels[index] < 0 THEN
14SET low TO low + 1
15END IF
16END IF
17
18SET index TO index + 1
19
20END WHILE
21
22SEND "Low readings: " & low TO DISPLAY
23SEND "Normal readings: " & (high + low) TO DISPLAY
24SEND "High readings: " & high TO DISPLAY
25
[1]

Develop code Questions

  1. IGCSE
  2. /Computer Science
  3. /Develop code