Skip to content
MathsGenie logo
Open app

Course home

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

Algorithms

EasyMedium
123456789101112131415161718192021222324252627
Question 7

A smart home monitoring system uses an algorithm to check the battery levels of various wireless sensors.

1 SET sensors TO ["hallway", "kitchen", "lounge", "bedroom", "garage", "garden"]
2
3 SET battery TO [0.12, 0.45, 0.08, 0.88, 0.02, 0.67]
4
5 SET index TO 0
6
7 WHILE index < 6 DO
8
9   IF (battery[index] < 0.1) THEN
10     SEND (sensors[index] & " low battery warning") TO DISPLAY
11
12   ELSE
13     IF (battery[index] >= 0.4) AND (battery[index] <= 0.6) THEN
14       SEND (sensors[index] & " check status") TO DISPLAY
15     END IF
16   END IF
17
18   SET index TO index + 1
19
20 END WHILE

The algorithm currently works with a fixed number of sensors.

Give the number of the line in the algorithm that would need to be amended to allow the algorithm to work for any number of sensors.

[1]

Algorithms Questions

  1. IGCSE
  2. /Computer Science
  3. /Algorithms