This algorithm calculates the price of a ticket.
age ← STRING_TO_INT(USERINPUT)
IF age < 5 THEN
price ← 0
ELSE IF age < 16 THEN
price ← 4
ELSE IF age ≥ 65 THEN
price ← 5
ELSE
price ← 9
ENDIF
OUTPUT priceState the output when the user enters:
(a) 3 [1]
(b) 16 [1]
(c) 70 [1]
(d) 15 [1]
- (a) 0(1)
- (b) 9(1)
- (c) 5(1)
- (d) 4(1)
- Answer: (a) 0 (b) 9 (c) 5 (d) 4
- Examiner tip: 16 is not less than 16, so it drops through to the ELSE. Check boundaries carefully.