← IGCSE Computer Science Paper 2

Writing an algorithm in pseudocode from a problem

To write an algorithm from a problem, DECLARE variables first, then INPUT, process with IF, CASE or a loop, then OUTPUT. Check each part against the problem and use the exam format.

Understanding Writing an algorithm in pseudocode from a problem in IGCSE Computer Science Paper 2

What it does: CASE OF is chosen when one variable is compared against several set values, as in a menu. A known number of repeats, such as 5 scores, means a count-controlled FOR loop is the correct structure. Declare your variables first. Then write INPUT, the process and OUTPUT in that order. There are two outcomes from one test, so use selection with IF. A FOR loop is for repeating a fixed number of times. Exam pseudocode has keywords in upper case and the type after a colon, for example DECLARE Age : INTEGER. INPUT is a keyword followed by the variable name that will store the value.

Common mistakes: A DECLARE statement needs a colon between the identifier and the data type. It should be DECLARE Num2 : INTEGER. The problem says a mark of 50 or more passes, but > leaves out a mark of exactly 50. The condition should be Mark >= 50.

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 problem says: 'Input two numbers and output their total.' Which line should come first in your algorithm?
OUTPUT TotalDECLARE Num1, Num2, Total : INTEGER
Matches
Total ← 0 INPUT Mark Total ← Total + Mark
↓
The variables Total and Mark are used but never declared. DECLARE Total : INTEGER and DECLARE Mark : INTEGER must come first.
Applying
Meanings
Term
DECLARE, INPUT, process, OUTPUT
Meaning
To write an algorithm from a problem, DECLARE variables first, then INPUT, process with IF, CASE or a loop, then OUTPUT. Check each part against the problem and use the exam format.
Practice
DECLARE Mark : INTEGER
Testing
Gaps
Mark : INTEGER
Check Answer
Spots
1DECLARE Num1 : INTEGER
2DECLARE Num2 INTEGER

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

The 'Starfish' badge — Five-Point Star, 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 problem says: 'Input two numbers and output their total.' Which line should come first in your algorithm?
A. OUTPUT Total
B. DECLARE Num1, Num2, Total : INTEGER ✓
Declare your variables first. Then write INPUT, the process and OUTPUT in that order.
2. Which is the correct order for writing an algorithm from a problem?
A. DECLARE, INPUT, process, OUTPUT ✓
B. OUTPUT, process, INPUT, DECLARE
Follow the order of the problem: set up the variables, take in the data, work on it, then show the result.
3. A problem says: 'Output 'Pass' if the mark is 50 or more, otherwise output 'Fail'.' Which structure fits?
A. FOR ... TO ... NEXT
B. IF ... THEN ... ELSE ... ENDIF ✓
There are two outcomes from one test, so use selection with IF. A FOR loop is for repeating a fixed number of times.
4. A problem says: 'Input 30 test marks and output the total.' Which structure should you choose for the process?
A. A FOR loop that repeats 30 times ✓
B. A CASE statement with 30 branches
The number of repeats is known (30), so a FOR loop is best. CASE is for choosing between set values.
5. A problem says: 'Input a menu choice of 1, 2 or 3 and output a different message for each.' Which structure is the neatest choice?
A. CASE Choice OF ... ENDCASE ✓
B. REPEAT ... UNTIL Choice = 3
One variable with several fixed values fits CASE. A loop would repeat the code, which the problem does not ask for.

Match the Pairs

DECLARE Total : INTEGER → Declare the variable and its data type at the start, before it is used in the algorithm
INPUT Mark IF Mark >= 50 THEN OUTPUT "Pass" ENDIF → Input a value, process it with a selection test from the problem, then output the result
The problem has several fixed choices for one value, so a CASE structure suits the process step → CASE OF Choice 1 : OUTPUT "Start" 2 : OUTPUT "Quit" ENDCASE
The problem says to repeat an action a set number of times, so a FOR loop is used for the process step → FOR Count ← 1 TO 5 INPUT Score NEXT Count
Total ← 0 INPUT Mark Total ← Total + Mark → The variables Total and Mark are used but never declared. DECLARE Total : INTEGER and DECLARE Mark : INTEGER must come first.
INPUT Age OUTPUT "Adult" IF Age >= 18 THEN → The statements are in the wrong order and the IF is incomplete. The IF must come before the OUTPUT, wrap it, and end with ENDIF.

Key Term

DECLARE, INPUT, process, OUTPUT
To write an algorithm from a problem, DECLARE variables first, then INPUT, process with IF, CASE or a loop, then OUTPUT. Check each part against the problem and use the exam format.

Fill in the Blanks

1. DECLARE Mark : INTEGER INPUT Mark OUTPUT Mark
Hint: The problem needs a whole-number mark stored. Type the keyword that sets up a variable before it is used.
2. DECLARE Age : INTEGER INPUT Age OUTPUT Age
Hint: The user must enter their age. Type the keyword that reads a value from the user into a variable.
3. IF Mark >= 50 THEN OUTPUT "Pass" ENDIF
Hint: The problem says to show Pass for 50 or more. Type the keyword that closes the selection structure.
4. FOR Count ← 1 TO 5 INPUT Score NEXT Count
Hint: Five scores are needed, so a count-controlled loop is used. Type the keyword that ends the FOR loop.
5. DECLARE Total : INTEGER Total ← 0 OUTPUT Total
Hint: The problem asks for the total to be shown at the end. Type the keyword that displays a result.

Spot the Error

Question 1
A DECLARE Num1 : INTEGER
B DECLARE Num2 INTEGER
C INPUT Num1
D INPUT Num2
E OUTPUT Num1 + Num2
Line B — A DECLARE statement needs a colon between the identifier and the data type. It should be DECLARE Num2 : INTEGER.
Question 2
A DECLARE Mark : INTEGER
B INPUT Mark
C IF Mark > 50 THEN
D OUTPUT "Pass"
E ENDIF
Line C — The problem says a mark of 50 or more passes, but > leaves out a mark of exactly 50. The condition should be Mark >= 50.
Question 3
A DECLARE Total : INTEGER
B DECLARE Num : INTEGER
C Total ← 1
D INPUT Num
E Total ← Total + Num
F OUTPUT Total
Line C — A running total must be set to 0 before anything is added, otherwise the answer is wrong by 1. It should be Total ← 0.
Question 4
A DECLARE Choice : INTEGER
B INPUT Choice
C CASE OF Choice
D 1 OUTPUT "Start"
E OTHERWISE : OUTPUT "Stop"
F ENDCASE
Line D — Each CASE branch needs a colon between the value and the statement. It should be 1 : OUTPUT "Start".
Question 5
A DECLARE Price : STRING
B DECLARE Total : REAL
C INPUT Price
D Total ← Price * 3
E OUTPUT Total
Line A — Price is used in a calculation and can have decimals, so it must be REAL. A STRING cannot be multiplied. It should be DECLARE Price : REAL.

Student with a class code? Join your class →