Worked example · IT · Year 7

Tracing a tuck shop till algorithm

DCF: Data and computational thinking → Problem-solving and modelling

What this is

A secure Year 7 response, annotated so you can see which success criterion each part meets. It is also the answer key. Key figures: Order A change 70p; Order B total 230p, change 270p; Order C change 5p; cheapest 3-item order 185p; a week of it £9.25 with 75p left; Ffion’s plan with toast £10.50, 50p over budget. The bugs are in box 6 and box 9.

Step 1: the shapes

Type of boxBox numberWhat happens
Input3 (or 8)The price of an item is typed in (box 8: the money paid).
Process4 (or 2, 7, 11)The price is added to the total and 1 is added to items.
Decision6 (or 5, 9)Asks if there are 3 or more items, to decide on the discount.
Output12 (or 10)Shows the change and the coins to give.

Any correct box number is fine. Evidences criterion 1.

Step 2: trace tables

Order A (Rhys)

BoxitemstotalpaidchangeOutput
200
4160
42130
82130200
11213020070
1270p: 50p, 20p

Order B (Ffion)

BoxitemstotalpaidchangeOutput
200
4190
42175
43255
73230
83230500
113230500270
12£2.70: £2, 50p, 20p

Order C (Osian)

BoxitemstotalpaidchangeOutput
200
41120
42205
82205200
10Not enough money
82205210
1122052105
125p: 5p

One row for every value that changes, in the order the boxes run. The pupil spots that box 7 only runs for Order B, and that Order C goes round the loop from box 10 back to box 8. Evidences criterion 2.

Step 3: the fewest coins

ChangeCoins givenNumber of coins
£2.70£2, 50p, 20p3
38p20p, 10p, 5p, 2p, 1p5
95p50p, 20p, 20p, 5p4
£3.65£2, £1, 50p, 10p, 5p5

Starting with the biggest coin uses up as much of the change as possible each time, so fewer coins are needed. If it started with 1p coins, 95p would be 95 coins.

Each line of coins adds up to the change (50 + 20 + 20 + 5 = 95). Evidences criteria 2 and 5.

Step 4: expected outputs

TestOrder and money paidExpected output and working
1Toast, water. Pays 200p.60 + 70 = 130. 200 − 130 = 70. Change 70p (50p, 20p).
2Toast, water, fruit pot. Pays 200p.60 + 70 + 80 = 210. 3 items, so 210 − 25 = 185. 200 − 185 = 15. Change 15p (10p, 5p).
3Flapjack. Pays 90p.Total 90. 90 is not less than 90, so no message. Change 0p, no coins.
4Cheese roll. Pays 100p.Total 120. 100 is less than 120, so “Not enough money”.
5Toast, toast, water, juice. Pays 300p.60 + 60 + 70 + 85 = 275. 4 items, so 275 − 25 = 250. Change 50p (50p).

The expected output is worked out from the rules, not from what the till does, which is the whole point of a test. Evidences criteria 3 and 5.

Step 5: the bugs

Tests 1, 4 and 5 pass. Tests 2 and 3 fail.

(a) Test 2 fails because Version 2 gave no discount for exactly 3 items: 210 is more than 200, so it said “Not enough money”. Box 6 probably says Is items more than 3? It should say Is items 3 or more?

Test 3 fails because paying exactly 90p for a 90p flapjack is enough. Box 9 probably says Is paid less than or equal to total? It should say Is paid less than total?

(b) 4 items is more than 3 and 3 or more, so both versions give the discount. The bug only shows at exactly 3. You have to test right on the edge of a rule, because that is where mistakes hide.

Each bug is linked to a numbered box with the wrong and the corrected wording, and the pupil explains why a test away from the edge missed it. Evidences criterion 4.

Step 6: a week on a budget

(a) The 3 cheapest items are toast, water and fruit pot: 60 + 70 + 80 = 210, minus 25 = 185p = £1.85.

(b) 185 × 5 = 925p = £9.25. 1,000 − 925 = 75p, so 75p is left.

(c) 90 + 85 = 175p a day. 175 × 5 = 875p = £8.75. With toast: 175 + 60 = 235, minus 25 = 210p. 210 − 175 = 35, so yes, it costs 35p more a day. But 210 × 5 = 1,050p = £10.50, which is 50p over her £10. She can only do it on 3 days: 3 × 210 + 2 × 175 = 630 + 350 = 980p.

DayItemsCost (pence)Discount?
MondayCheese roll, water120 + 70 = 190No
TuesdayToast, fruit pot, water210 − 25 = 185Yes
WednesdayFlapjack, water90 + 70 = 160No
ThursdayToast, juice, fruit pot225 − 25 = 200Yes
FridayCheese roll, juice120 + 85 = 205No
Week total 940p = £9.40Left from £10: 60p

Working is shown in pence and every answer is converted to pounds. In (c) the pupil checks Ffion’s claim, then sees that a small daily cost adds up over a week. Evidences criterion 5.

If you finish early: answers

New rule: decision box Is total more than 300?, Yes goes to process box total = total − total ÷ 10. For £3.20, 10% is 32p, which beats 25p by 7p.

Test 1 would catch it: 130 − 200 = −70, so the till would show change of −70p, which makes no sense.

Why this response is secure