A good description of a correction has four parts: where the fault is, what is wrong, why it causes the wrong result, and what to change. Code alone shows only the last part, and markers cannot tell whether you understood the fault or copied a line.
This lesson sits in the problem-solving explanations module. It follows from justifying test cases, because a failing test is how most faults are found.
What does a full description contain?
- Where: the line number or the statement, for example “line 6”.
- What is wrong: the exact thing, such as a wrong divisor, a wrong comparison, a missing statement or a wrong loop limit.
- Why it matters: the effect on the output, ideally with a value from the test data.
- The change: the smallest fix, in words, optionally with the corrected line.
Use evidence from the requirement: “the requirement says average of three numbers, but the code divides by 2”.
Worked example
Requirement: read three numbers and output their average.
1 Total ← 0
2 FOR Index ← 1 TO 3
3 INPUT Number
4 Total ← Total + Number
5 NEXT Index
6 Average ← Total / 2
7 OUTPUT Average
Test data 4, 6, 8 should give 6 (since 4 + 6 + 8 = 18 and 18 / 3 = 6). The program outputs 9.
Where: line 6.
What is wrong: Total is divided by 2, but three numbers were entered.
Why it matters: with the test data, 18 / 2 = 9, which is not the expected 6.
The change: divide by 3, the number of values read. A safer change is to divide by a variable that counts the entries, so the line still works if the loop limit changes. Corrected line: Average ← Total / 3.
Check the fix. With 4, 6, 8: 18 / 3 = 6. This matches the expected result.
The mistake to watch for
A weak answer is:
The program is wrong because the average is not right. Change it so it gives the right average.
It gives no line, no fault and no change. A second weak style rewrites all seven lines with a different structure, so the marker cannot see what was actually wrong.
The correction: “Line 6 divides Total by 2, but three values are entered, so the output for 4, 6, 8 is 9 instead of 6. Change the divisor to 3.”
Check yourself
1. This code should add the whole numbers 1 to 10 (the answer is 55), but it outputs 45. Describe the correction.
1 Total ← 0
2 FOR N ← 1 TO 9
3 Total ← Total + N
4 NEXT N
5 OUTPUT Total
Show answer
Line 2 has the wrong upper limit. The loop stops at 9, so 10 is never added, and the total is 1 + 2 + … + 9 = 45 instead of 55. Change the limit from 9 to 10: FOR N ← 1 TO 10.
2. The rule is “output Pass for a mark of 50 or more”. A mark of 50 gives no output. Describe the correction.
1 INPUT Mark
2 IF Mark > 50 THEN
3 OUTPUT "Pass"
4 ENDIF
Show answer
Line 2 uses >, which excludes 50, but the rule says “50 or more”. A mark of exactly 50 fails the test, so “Pass” is not output. Change > to >=: IF Mark >= 50 THEN.
3. The code should output the total cost of three item prices (5, 6 and 7, so 18) but outputs 7. Describe the correction.
1 Total ← 0
2 FOR I ← 1 TO 3
3 INPUT Price
4 Total ← Price
5 NEXT I
6 OUTPUT Total
Show answer
Line 4 assigns Price to Total instead of adding it, so each pass overwrites the previous value and only the last price, 7, remains. Change it to Total ← Total + Price so the prices accumulate: 5, 11, 18.
Where this leads next
Once you can describe a fix, learn to show why a program gives its output in connecting a trace with the final output. The restricted pseudocode trace trainer can help you test a fix before you describe it.
If you often spot the error but lose marks on how you explain the fix, our teachers can work through your wording in online one-to-one Computer Science tuition.