← IGCSE Computer Science Paper 2

Turning a structure diagram into pseudocode

Each box in a structure diagram becomes a PROCEDURE or FUNCTION named after the box. A box with sub-boxes uses CALL statements to run them. Check that every box has code.

Understanding Turning a structure diagram into pseudocode in IGCSE Computer Science Paper 2

What it does: The parent box becomes a routine whose body is one CALL for each of its sub-boxes, in order. A bottom-level box has no sub-boxes, so it holds the real code. If it produces a value, it is written as a FUNCTION with RETURN. Each box becomes a subroutine named after the box, so the code is easy to match back to the diagram. Calling a procedure needs the CALL keyword followed by its name and brackets. Always check that every box in the diagram has code. A missing box means part of the solution is missing. In Cambridge pseudocode, a sub-box's procedure is run by a CALL statement, so the line should be CALL GetMarks().

Common mistakes: The box name becomes the subroutine name, so the CALL must match it exactly. The procedure is SoundAlarm, so the line should be CALL SoundAlarm(). The top box only calls its sub-boxes and returns no value, so it is a PROCEDURE, which also matches ENDPROCEDURE. The line should be PROCEDURE Main().

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 136–145) and word search (Modules 123–145).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A structure diagram has a box called 'Get Marks'. What is the best way to turn this box into pseudocode?
PROCEDURE GetMarks() ... ENDPROCEDUREPROCEDURE x() ... ENDPROCEDURE
Matches
PROCEDURE Main() CALL GetMarks() ENDPROCEDURE // the diagram also has Show Result
↓
The box Show Result has no CALL statement in Main, so one box has no code. Every box in the diagram must be checked and given code.
Applying
Meanings
Term
PROCEDURE
Meaning
Each box in a structure diagram becomes a PROCEDURE or FUNCTION named after the box. A box with sub-boxes uses CALL statements to run them. Check that every box has code.
Practice
PROCEDURE PlayGame()
Testing
Gaps
ShowMenu()
Check Answer
Spots
3ENDPROCEDURE
4CALL SoundAlarms()

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 structure diagram has a box called 'Get Marks'. What is the best way to turn this box into pseudocode?
A. PROCEDURE GetMarks() ... ENDPROCEDURE ✓
B. PROCEDURE x() ... ENDPROCEDURE
Each box becomes a subroutine named after the box, so the code is easy to match back to the diagram.
2. A box in the structure diagram has three sub-boxes. How does its pseudocode run the sub-boxes?
A. It copies all the sub-box code inside itself
B. It uses three CALL statements, one per sub-box ✓
A box above others becomes a routine that calls its sub-boxes. This keeps each part separate and reusable.
3. Which box in a structure diagram becomes a routine that contains the real steps (INPUT, calculations, OUTPUT)?
A. The top box that has sub-boxes under it
B. A bottom-level box with no sub-boxes ✓
Bottom-level boxes do the actual work. Boxes above them mainly call the routines below.
4. The top box 'Run Quiz' has sub-boxes 'Ask Question' and 'Show Score'. Which is the correct pseudocode?
A. PROCEDURE RunQuiz() CALL AskQuestion() CALL ShowScore() ENDPROCEDURE ✓
B. PROCEDURE RunQuiz() AskQuestion ShowScore ENDPROCEDURE
Calling a procedure needs the CALL keyword followed by its name and brackets.
5. After converting a structure diagram, you find one box has no matching PROCEDURE or FUNCTION. What should you do?
A. Write a subroutine for that box so every box has code ✓
B. Ignore it because the other boxes are enough
Always check that every box in the diagram has code. A missing box means part of the solution is missing.

Match the Pairs

PROCEDURE GetMarks() → A bottom-level box called Get Marks becomes a procedure with the same name
CALL GetMarks() → A parent box runs its sub-box by calling the sub-box's procedure
A box at the top of a structure diagram with three sub-boxes becomes a routine that makes three CALL statements → PROCEDURE Main() CALL GetMarks() CALL Calculate() CALL ShowResult() ENDPROCEDURE
A bottom-level box that works out and gives back a value becomes a FUNCTION that RETURNS it → FUNCTION Average(Total : INTEGER) RETURNS REAL RETURN Total / 3 ENDFUNCTION
PROCEDURE Main() CALL GetMarks() ENDPROCEDURE // the diagram also has Show Result → The box Show Result has no CALL statement in Main, so one box has no code. Every box in the diagram must be checked and given code.
PROCEDURE Main() GetMarks() ENDPROCEDURE → The sub-box is run without the CALL keyword. A procedure must be run with CALL GetMarks().

Key Term

PROCEDURE
Each box in a structure diagram becomes a PROCEDURE or FUNCTION named after the box. A box with sub-boxes uses CALL statements to run them. Check that every box has code.

Fill in the Blanks

1. PROCEDURE ShowMenu() OUTPUT "Menu" ENDPROCEDURE
Hint: Type the keyword that starts the subroutine for a bottom-level box that only does a task and returns no value.
2. PROCEDURE RunGame() CALL GetName() ENDPROCEDURE
Hint: Type the keyword a higher-level box uses to run one of its sub-boxes.
3. PROCEDURE ShowScore() OUTPUT "Score: ", Score ENDPROCEDURE
Hint: Type the subroutine name taken from a box labelled Show Score, written as one word with no spaces.
4. FUNCTION CalcTotal() RETURNS INTEGER RETURN Price * Qty ENDFUNCTION
Hint: Type the keyword for a box whose code must give a value back to the box above it.
5. PROCEDURE SaveData() OUTPUT "Saved" ENDPROCEDURE
Hint: Type the keyword that closes the code for a box, so you can check every box has complete code.

Spot the Error

Question 1
A PROCEDURE SoundAlarm()
B OUTPUT "Alarm!"
C ENDPROCEDURE
D CALL SoundAlarms()
Line D — The box name becomes the subroutine name, so the CALL must match it exactly. The procedure is SoundAlarm, so the line should be CALL SoundAlarm().
Question 2
A FUNCTION Main()
B CALL ReadTemp()
C CALL CheckTemp()
D ENDPROCEDURE
Line A — The top box only calls its sub-boxes and returns no value, so it is a PROCEDURE, which also matches ENDPROCEDURE. The line should be PROCEDURE Main().
Question 3
A PROCEDURE RunShop()
B ScanItem()
C CALL PrintBill()
D ENDPROCEDURE
Line B — A box above other boxes runs its sub-boxes using CALL statements. The line should be CALL ScanItem().
Question 4
A FUNCTION Sum() RETURNS INTEGER
B Total ← Maths + English
C OUTPUT Total
D ENDFUNCTION
Line C — A box that becomes a FUNCTION must send its answer back with RETURN. It should be RETURN Total, not OUTPUT Total.
Question 5
A PROCEDURE Main()
B CALL GetMarks()
C Total ← CALL Sum()
D CALL ShowTotal()
E ENDPROCEDURE
Line C — CALL is only used to run a PROCEDURE. A FUNCTION is used inside an expression, so the line should be Total ← Sum().

Student with a class code? Join your class →