Six original Cambridge-style questions on identifying and correcting errors in algorithms.
This algorithm should input 5 prices and output the total and the number of prices over 20. Identify the two errors and write the corrected lines.
01 Total ← 0 02 Over ← 0 03 FOR Count ← 1 TO 5 04 INPUT Price 05 Total ← Price 06 IF Price > 20 07 THEN 08 Over ← Over + Price 09 ENDIF 10 NEXT Count 11 OUTPUT Total, " ", Over
This algorithm should output the numbers 1 to 10. Identify the error and correct it.
Number ← 1
WHILE Number <= 10 DO
OUTPUT Number
ENDWHILEThis algorithm should find the largest of 8 temperatures, which can be from -30 to 40. Explain the error and give two different ways to correct it.
Largest ← 50
FOR Day ← 1 TO 8
INPUT Temp
IF Temp > Largest
THEN
Largest ← Temp
ENDIF
NEXT Day
OUTPUT LargestThis loop should run 12 times: FOR Month ← 1 TO 11. State the problem and correct the line.
This should swap the values of A and B. A = 4 and B = 9 at the start. State the values after the code runs, explain the error and correct it.
A ← B B ← A
This validation should reject marks outside 0 to 100: UNTIL Mark >= 0 OR Mark <= 100. Explain why it accepts every number, and correct it.
Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.