← IGCSE Computer Science Paper 2

Amending an algorithm

Find the part that must change for the new requirement, change only that part, then re-trace the algorithm to check the rest still works.

Understanding Amending an algorithm in IGCSE Computer Science Paper 2

What it does: Adding a new input is a sub-theme of amending. Add the new INPUT (and prompt) without rewriting the rest. Adding a decision to an existing algorithm uses an IF ... ENDIF that holds the new action. The old code stays as it is. Amend only the part that must change. Here that is the limit in the condition. The rest of the algorithm can stay the same. The perimeter needs a new calculation and a new OUTPUT statement. The existing area calculation does not need to change. A small change can still break other parts. Re-tracing with test data shows whether the whole algorithm still gives the right outputs.

Common mistakes: The requirement changed the pass mark to 40, but the condition still uses the old limit 50. Only this limit should change: IF Mark >= 40. A third input was added, but the new value Mark3 is not included in the total. The line should be Total ← Mark1 + Mark2 + Mark3 so that dividing by 3 gives the correct mean.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 254–264) and word search (Modules 254–274).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A program outputs 'Pass' if Mark >= 50. The new requirement says the pass mark is now 60. What should you amend?
Rewrite the whole program from the startChange only the condition to Mark >= 60
Matches
Pass mark changed from 50 to 60 in the IF line, but OUTPUT still says "Pass is 50 or more"
↓
The student changed the condition but did not check the rest of the algorithm, so the message is now wrong.
Applying
Meanings
Term
amend an algorithm
Meaning
Find the part that must change for the new requirement, change only that part, then re-trace the algorithm to check the rest still works.
Practice
DECLARE Mark : INTEGER
Testing
Gaps
Passed ← Mark 60
Check Answer
Spots
2INPUT Mark
3IF Mark >= 50

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Octopus' badge — Multi-Tasker, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A program outputs 'Pass' if Mark >= 50. The new requirement says the pass mark is now 60. What should you amend?
A. Rewrite the whole program from the start
B. Change only the condition to Mark >= 60 ✓
Amend only the part that must change. Here that is the limit in the condition. The rest of the algorithm can stay the same.
2. A loop is FOR Count ← 1 TO 5 and must now read 8 numbers. Which amendment is correct?
A. FOR Count ← 1 TO 8 ✓
B. FOR Count ← 1 TO 5 and add 3 more INPUT lines after the loop
Changing the loop limit from 5 to 8 is the smallest change that meets the new requirement. Extra INPUT lines would be clumsy and could go wrong.
3. An algorithm inputs Length and Width and outputs the area. The new requirement is to also output the perimeter. What kind of amendment is this?
A. Adding a new process and a new output ✓
B. Changing a loop limit
The perimeter needs a new calculation and a new OUTPUT statement. The existing area calculation does not need to change.
4. After you amend an algorithm, what should you do last?
A. Assume it works because the change was small
B. Re-trace it to check the rest still works ✓
A small change can still break other parts. Re-tracing with test data shows whether the whole algorithm still gives the right outputs.
5. A program outputs 'Adult' for Age >= 18. The new requirement says to also output 'Senior' when Age >= 65. What should you add?
A. A new decision, such as a nested IF or an extra condition ✓
B. A new variable declared with DECLARE and nothing else
A new outcome based on a condition needs a new decision. The extra IF or condition must be placed so the existing 'Adult' output still works.

Match the Pairs

IF Mark >= 50 THEN → IF Mark >= 60 THEN → Amending a condition so the pass mark changes from 50 to 60. Only the limit in this one line changes.
Re-trace with Mark = 60, 59 and 61 → Re-checking the amended algorithm with test data to make sure the rest still works.
The new requirement needs one more value from the user, so add a new input. → OUTPUT "Enter the bonus" INPUT Bonus
The new requirement needs a different action for large numbers, so add a decision. → IF Total > 100 THEN OUTPUT "Large" ENDIF
Pass mark changed from 50 to 60 in the IF line, but OUTPUT still says "Pass is 50 or more" → The student changed the condition but did not check the rest of the algorithm, so the message is now wrong.
Amended algorithm was handed in without a trace, so a loop limit of 10 was left in place of the new limit of 20 → The student did not re-trace the amended algorithm, so they missed that the loop still runs the old number of times.

Key Term

amend an algorithm
Find the part that must change for the new requirement, change only that part, then re-trace the algorithm to check the rest still works.

Fill in the Blanks

1. // Amended: pass mark is now 60 or more Passed ← Mark >= 60 OUTPUT Passed
Hint: Type the relational operator that means 'greater than or equal to' to change the condition.
2. // Amended: also ask for the student's age INPUT Name INPUT Age
Hint: Type the keyword that reads a new value from the user.
3. Total ← Price * Quantity // Amended: also show the total OUTPUT Total
Hint: Type the keyword that displays a value to the user.
4. IF Total > 100 THEN Total ← Total - 10 ENDIF
Hint: Type the keyword that closes the new decision you have added.
5. // Re-trace: reset the running total first Total ← 0 Total ← Total + Mark
Hint: Type the name of the variable that holds the running total.

Spot the Error

Question 1
A // Pass mark is now 40
B INPUT Mark
C IF Mark >= 50
D THEN
E OUTPUT "Pass"
F ENDIF
Line C — The requirement changed the pass mark to 40, but the condition still uses the old limit 50. Only this limit should change: IF Mark >= 40.
Question 2
A INPUT Mark1
B INPUT Mark2
C INPUT Mark3
D Total ← Mark1 + Mark2
E Mean ← Total / 3
F OUTPUT Mean
Line D — A third input was added, but the new value Mark3 is not included in the total. The line should be Total ← Mark1 + Mark2 + Mark3 so that dividing by 3 gives the correct mean.
Question 3
A // Record 7 days, not 5
B FOR Day ← 1 TO 5
C INPUT Temp
D OUTPUT Temp
E NEXT Day
Line B — The comment says the algorithm must now cover 7 days, so the loop limit must be changed from 5 to 7: FOR Day ← 1 TO 7.
Question 4
A INPUT Age
B Fare ← 5
C IF Age ← 16
D THEN
E Fare ← 2
F ENDIF
Line C — The new decision for under-16s must be a comparison, not an assignment. ← stores a value; the condition should use the relational operator <: IF Age < 16.
Question 5
A Total ← 0
B Count ← 0
C FOR Num ← 1 TO 5
D Total ← Total + 1
E Count ← Count + 1
F NEXT Num
Line D — Re-tracing after the amendment shows Total only goes up by 1 each time, giving 5 instead of 15. The total must add the loop value: Total ← Total + Num.

Student with a class code? Join your class →