Structured programming and subroutines (procedures and functions)

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142
Question 40
Easy

State how many times the subroutine DISPENSE will be called with the parameter 'water' if the user input is 'dry' in Figure 1.

Figure 1

1      dryness_level ← USERINPUT
2      IF dryness_level = 'damp' THEN
3          cycles ← 3
4      ELSE IF dryness_level = 'dry' THEN
5          cycles ← 7
6      ELSE IF dryness_level = 'arid' THEN
7          cycles ← 11
8      ELSE
9          OUTPUT 'invalid reading'
10     ENDIF
11     FOR k ← 1 TO cycles
12         IF k <= 3 THEN
13             DISPENSE('fertilizer')
14         ELSE
15             DISPENSE('water')
16         ENDIF
17     ENDFOR
[1]

Structured programming and subroutines (procedures and functions) Questions

  1. GCSE
  2. /Computer Science
  3. /Structured programming and subroutines (procedures and functions)