Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8.
Follow the flowchart. Each Y takes 1 off Stock and adds 1 to Total. When Stock goes below 5, it outputs a message and adds 10. The N ends the algorithm and outputs Total.
| Stock | Total | Sale | OUTPUT |
|---|---|---|---|
| 10 | 0 | ||
| 9 | 1 | Y | |
| 8 | 2 | Y | |
| 7 | 3 | Y | |
| 6 | 4 | Y | |
| 5 | 5 | Y | |
| 4 | Y | Add new stock | |
| 14 | 6 | ||
| N | |||
| 6 |
Stock column correct [1]
Total column correct [1]
Sale column correct [1]
OUTPUT column correct [1]
Add an input for how many wheelbarrows are sold. Any three of these:
Input a number (quantity) sold [1]
Check that the number is less than or equal to the Stock, after checking that Sale is not "N" [1]
Update Stock by that number: Stock ← Stock - Number [1]
Update Total by that number: Total ← Total + Number (also credited, but only three marks are available).
▶ 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.