GCSEBeast

Trace tables and errors

GCSE Computer Science practice questions on trace tables and errors. Try 3 for free below — with hints, the answer and why the wrong answers are tempting. GCSE Beast has 20 questions on this topic.

Question 1 of 3Difficulty ●●●●●

A café loyalty card holds stamps. When a card has 9 or more stamps, the customer gets a free drink and 9 stamps are taken off the card.

This pseudocode runs when a customer with 7 stamps buys 5 drinks:

Stamps ← 7Bought ← 5Stamps ← Stamps + BoughtIF Stamps >= 9 THEN Stamps ← Stamps - 9 OUTPUT "Free drink!"ENDIF

What is the value of Stamps after the pseudocode has run?

Question 2 of 3Difficulty ●●●●●

A football academy times 20 players over 100 m. This algorithm should input each player's time, in seconds, and output the fastest (lowest) time.

DECLARE Fastest : REALDECLARE Time : REALDECLARE Runner : INTEGERFastest ← 0FOR Runner ← 1 TO 20 INPUT Time IF Time < Fastest THEN Fastest ← Time ENDIFNEXT RunnerOUTPUT "Fastest time: ", Fastest

When it is tested with real times, it always outputs 0. Which line contains the error?

Question 3 of 3Difficulty ●●●●●

A bus-pass top-up machine accepts only coins worth 1, 2 or 5. A top-up costs 10.

Paid ← 0Rejected ← 0REPEAT INPUT Coin IF Coin = 1 OR Coin = 2 OR Coin = 5 THEN Paid ← Paid + Coin ELSE Rejected ← Rejected + 1 ENDIFUNTIL Paid >= 10

The coins entered are, in this order: 2, 3, 5, 20, 1, 2, 2, 5

What are the values of Paid and Rejected when the loop ends?