Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 8 of 8.
Input both numbers, work out the total with the booking fee, and output it.
OUTPUT "Please enter the number of adult tickets " INPUT Adult OUTPUT "Please enter the number of child tickets " INPUT Child Total ← (Adult * 12.99) + (Child * 7.99) + 1.99 OUTPUT "The total cost is ", Total
Input of the number of adult tickets and child tickets [1]
Total of adult and child ticket costs calculated [1]
Booking fee of 1.99 added [1]
Total output with an appropriate message [1]
Put the adult input inside a loop that repeats while the number is too small.
REPEAT
OUTPUT "You need at least one adult ticket. Enter the number of adult tickets "
INPUT Adult
UNTIL Adult >= 1Add a REPEAT ... UNTIL loop (or a WHILE loop) [1]
With the correct condition, for example UNTIL Adult >= 1 (or WHILE Adult < 1) [1]
With a suitable message asking the user to enter the number again [1]
The INPUT of Adult is inside the loop so it is asked again each time [1]
The person needs A (tall enough) AND B (old enough) AND NOT C (no medical condition).
Write: X = (A AND B) AND (NOT C)
A AND B [1]
AND NOT C [1]
X is 1 only when A = 1, B = 1 and C = 0.
| A | B | C | A AND B | NOT C | X |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 |
X correct in rows 1 and 2 [1]
X correct in rows 3 and 4 [1]
X correct in rows 5 and 6 [1]
X correct in rows 7 and 8 [1]
▶ Topic lesson
A lesson on this topic · by Mr Bulmer's Learning Zone. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.