← IGCSE Computer Science Paper 2

Subroutines make programs easier to test and read

A program split into small named subroutines. Each one can be tested alone and read quickly, so errors are easier to find and the whole program is easier to understand.

Understanding Subroutines make programs easier to test and read in IGCSE Computer Science Paper 2

What it does: The name IsPassMark tells the reader what the function does, which makes the program easier to read. Each line is one named step, so the whole program can be understood at a glance. Testing one small subroutine alone narrows the search for a bug to that subroutine only, instead of the whole program. A short main program made of subroutine calls reads like a list of steps, so the overall plan is clear at a glance. Each programmer can write and test their own subroutines separately, then the parts are combined in the main program. If the subroutine is tested alone and gives the wrong answer, the error must be inside it, so there is far less code to check.

Common mistakes: Testing Half on its own with the input 10 should give 5, but N * 2 gives 20. Because the function is small and separate, the fault is easy to find. The line should be RETURN N / 2. The main program is a list of steps, and each step must start with CALL to run a procedure. Line 2 should be CALL FindAverage().

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 439–448) and word search (Modules 439–458).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A program is split into small named subroutines. Why does this make errors easier to find?
The computer automatically fixes errors inside subroutinesEach subroutine can be tested on its own, so the faulty one is quickly located
Matches
PROCEDURE DoStuff() // 80 lines: input, maths and output ENDPROCEDURE
↓
One large subroutine with a vague name does many jobs, so it is hard to read and an error is hard to locate. Split it into small subroutines with descriptive names.
Applying
Meanings
Term
modular program
Meaning
A program split into small named subroutines. Each one can be tested alone and read quickly, so errors are easier to find and the whole program is easier to understand.
Practice
FUNCTION IsPassMark(Mark : INTEGER) RETURNS BOOLEAN
Testing
Gaps
ShowMenu()
Check Answer
Spots
1FUNCTION Half(N) RETURNS REAL
2 RETURN N * 2

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

The 'Badger' badge — Determined Digger, 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 is split into small named subroutines. Why does this make errors easier to find?
A. The computer automatically fixes errors inside subroutines
B. Each subroutine can be tested on its own, so the faulty one is quickly located ✓
Testing one small subroutine alone narrows the search for a bug to that subroutine only, instead of the whole program.
2. Which subroutine name best shows its purpose?
A. CalculateAverage ✓
B. DoStuff
A descriptive name such as CalculateAverage tells the reader what the subroutine does without reading its code.
3. How could you test a function called IsPrime on its own?
A. Call it with different test inputs and check each returned value ✓
B. Run the whole program and hope IsPrime is used somewhere
Testing one subroutine alone means giving it its own inputs and checking its output against what you expect.
4. Which main program is easier to read?
A. One block of 200 lines with no subroutines
B. CALL GetNames() then CALL SortNames() then CALL ShowNames() ✓
A short main program made of subroutine calls reads like a list of steps, so the overall plan is clear at a glance.
5. True or false: Splitting a program into subroutines lets several programmers work on different parts at the same time.
A. True ✓
B. False
Each programmer can write and test their own subroutines separately, then the parts are combined in the main program.

Match the Pairs

CALL ShowMenu() → A main program line that reads like a step in a list and tells the reader what happens without showing the detail
OUTPUT CalcTotal(5, 3) → Tests one subroutine alone by giving it known inputs and checking the output is what you expect
A descriptive name shows the purpose of a subroutine, so a reader understands it without reading its code → FUNCTION IsPassMark(Score : INTEGER) RETURNS BOOLEAN
A short main program can read like a list of steps because each step is a named subroutine → CALL GetScores() CALL ShowResults()
PROCEDURE DoStuff() // 80 lines: input, maths and output ENDPROCEDURE → One large subroutine with a vague name does many jobs, so it is hard to read and an error is hard to locate. Split it into small subroutines with descriptive names.
PROCEDURE P1() PROCEDURE P2() → Names like P1 and P2 do not show purpose, so other programmers working on different subroutines cannot tell what each one does. Use descriptive names such as ReadMarks.

Key Term

modular program
A program split into small named subroutines. Each one can be tested alone and read quickly, so errors are easier to find and the whole program is easier to understand.

Fill in the Blanks

1. CALL ShowMenu() CALL GetChoice() CALL ShowResult()
Hint: Type the keyword that runs a procedure, so the main program reads like a list of steps.
2. FUNCTION IsEven(N : INTEGER) RETURNS BOOLEAN RETURN N MOD 2 = 0 ENDFUNCTION
Hint: Type the data type this function returns. The descriptive name and the comparison show what kind of value it gives back.
3. // Test: Square(5) should give 25 OUTPUT Square(5)
Hint: Type the test input value named in the comment, so this one subroutine can be tested alone.
4. PROCEDURE DisplayScore(Score : INTEGER) OUTPUT "Score: ", Score ENDPROCEDURE
Hint: Type the keyword that closes a procedure definition so one programmer's subroutine has a clear end.
5. FUNCTION IsPass(M : INTEGER) RETURNS BOOLEAN RETURN M >= 50 ENDFUNCTION
Hint: Type the keyword that sends a value back to the caller, so this small function can be checked on its own.

Spot the Error

Question 1
A FUNCTION Half(N) RETURNS REAL
B RETURN N * 2
C ENDFUNCTION
D OUTPUT Half(10)
Line B — Testing Half on its own with the input 10 should give 5, but N * 2 gives 20. Because the function is small and separate, the fault is easy to find. The line should be RETURN N / 2.
Question 2
A CALL ReadMarks()
B FindAverage()
C CALL ShowResult()
Line B — The main program is a list of steps, and each step must start with CALL to run a procedure. Line 2 should be CALL FindAverage().
Question 3
A FUNCTION Tax(P) RETURNS REAL
B OUTPUT P * 0.2
C ENDFUNCTION
Line B — A function must RETURN its value so that it can be tested alone and used by other code. OUTPUT only displays the number. The line should be RETURN P * 0.2.
Question 4
A PROCEDURE ShowTotal(T)
B OUTPUT "Total: ", T
C ENDPROCEDURE
D CALL ShowTotal()
Line D — To test the procedure alone you must give it its own input. ShowTotal has one parameter, so the call needs a value, for example CALL ShowTotal(50).
Question 5
A FUNCTION Area(W) RETURN REAL
B RETURN W * W
C ENDFUNCTION
Line A — The header of a function must use the keyword RETURNS before the data type. The line should be FUNCTION Area(W) RETURNS REAL.

Student with a class code? Join your class →