← IGCSE Computer Science Paper 2

Writing an algorithm for a described problem

To solve a described problem, list the inputs, pick the standard method, then write it: DECLARE variables, set start values, loop through the data, and OUTPUT the result.

Understanding Writing an algorithm for a described problem in IGCSE Computer Science Paper 2

What it does: The average is the total divided by the count, calculated after the loop, and then displayed with OUTPUT. Counting only items that meet a condition uses an IF inside the loop to increase the counter by 1. A running total must start at 0 so that only the marks are added. Starting at 30 (the number of marks) would make the answer wrong. Highest means maximum. A sort would reorder the whole list, but the problem only asks for one value. Meaningful identifier names such as PassCount make an algorithm easier to read and mark. A single letter tells you nothing.

Common mistakes: This line replaces Total with each mark instead of adding to it, so the loop ends with only the last mark. It should be Total ← Total + Mark[i]. The class has 5 marks, but the loop stops at 4, so the fifth mark is never added to the total. It should be FOR i ← 1 TO 5.

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 307–316) and word search (Modules 296–316).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A teacher wants the total of 30 marks. Which start value is correct for the total before the loop?
Total ← 0Total ← 30
Matches
FOR Index ← 1 TO 30 Total ← 0 Total ← Total + Marks[Index] NEXT Index
↓
Total is reset to 0 inside the loop, so it is wiped on every repeat and only the last mark is kept. The start value must be set before the loop.
Applying
Meanings
Term
DECLARE, loop, OUTPUT
Meaning
To solve a described problem, list the inputs, pick the standard method, then write it: DECLARE variables, set start values, loop through the data, and OUTPUT the result.
Practice
DECLARE Total : INTEGER
Testing
Gaps
Total : INTEGER
Check Answer
Spots
3FOR i ← 1 TO 5
4 Total ← Mark[i]

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

The 'Ermine' badge — Tundra Streak, 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 teacher wants the total of 30 marks. Which start value is correct for the total before the loop?
A. Total ← 30
B. Total ← 0 ✓
A running total must start at 0 so that only the marks are added. Starting at 30 (the number of marks) would make the answer wrong.
2. A problem says: 'Find the highest mark in a class of 25 students.' Which standard method is needed?
A. Bubble sort
B. Finding the maximum ✓
Highest means maximum. A sort would reorder the whole list, but the problem only asks for one value.
3. Which is the better identifier name for a variable that stores the number of students who passed?
A. PassCount ✓
B. x
Meaningful identifier names such as PassCount make an algorithm easier to read and mark. A single letter tells you nothing.
4. Which order is best when writing an algorithm for a described problem?
A. List the inputs, choose the standard method, then write the pseudocode ✓
B. Write the loop first, then work out what the problem is asking
First understand the problem: what are the inputs and which standard method does it need? Then write DECLARE, start values, the loop and OUTPUT.
5. A class has 30 marks stored in an array. To calculate the average mark, what should the algorithm do after the loop has finished?
A. Divide Total by the number of marks, then OUTPUT the result ✓
B. Divide Total by the number of marks inside the loop on every repeat
Average = total ÷ count. The total is only complete when the loop ends, so the division and OUTPUT go after ENDFOR (or NEXT).

Match the Pairs

DECLARE Total : INTEGER Total ← 0 → Declare the variable and set its start value to 0 before the loop, so the running total begins correctly.
FOR Index ← 1 TO 30 Total ← Total + Marks[Index] NEXT Index → Loop through all 30 marks in the array and add each one to the running total.
After the loop has finished, work out the class average from the total and the number of marks, then show it. → Average ← Total / 30 OUTPUT "Average: ", Average
To count the passes, start a counter at 0 and add 1 only when a mark meets the pass condition. → IF Marks[Index] >= 50 THEN Passes ← Passes + 1 ENDIF
FOR Index ← 1 TO 30 Total ← 0 Total ← Total + Marks[Index] NEXT Index → Total is reset to 0 inside the loop, so it is wiped on every repeat and only the last mark is kept. The start value must be set before the loop.
Highest ← 0 FOR Index ← 1 TO 30 IF Marks[Index] < Highest THEN Highest ← Marks[Index] ENDIF NEXT Index → The comparison uses < instead of >, so this finds the lowest mark rather than the highest. It should be Marks[Index] > Highest.

Key Term

DECLARE, loop, OUTPUT
To solve a described problem, list the inputs, pick the standard method, then write it: DECLARE variables, set start values, loop through the data, and OUTPUT the result.

Fill in the Blanks

1. DECLARE Total : INTEGER
Hint: Type the keyword that creates a variable before the algorithm uses it.
2. DECLARE Total : INTEGER Total ← 0
Hint: Type the start value a running total needs before any marks are added.
3. FOR Index ← 1 TO 30 Total ← Total + Marks[Index] NEXT Index
Hint: Type the loop counter variable that picks each element of the array.
4. OUTPUT "Highest mark: ", Highest
Hint: Type the keyword that displays the final result to the user.
5. IF Marks[Index] >= 50 THEN Passes ← Passes + 1 ENDIF
Hint: Type the comparison operator meaning greater than or equal to, so a mark of exactly 50 is counted as a pass.

Spot the Error

Question 1
A DECLARE Total : INTEGER
B Total ← 0
C FOR i ← 1 TO 5
D Total ← Mark[i]
E NEXT i
F OUTPUT Total
Line D — This line replaces Total with each mark instead of adding to it, so the loop ends with only the last mark. It should be Total ← Total + Mark[i].
Question 2
A Total ← 0
B FOR i ← 1 TO 4
C Total ← Total + Mark[i]
D NEXT i
E Average ← Total / 5
F OUTPUT Average
Line B — The class has 5 marks, but the loop stops at 4, so the fifth mark is never added to the total. It should be FOR i ← 1 TO 5.
Question 3
A Found ← FALSE
B FOR i ← 1 TO 5
C IF Name[i] ← Target THEN
D Found ← TRUE
E ENDIF
F NEXT i
Line C — The arrow ← is for assignment. A search condition must compare values with =, so it should be IF Name[i] = Target THEN.
Question 4
A IF Score[1] > Score[2] THEN
B Temp ← Score[2]
C Score[1] ← Score[2]
D Score[2] ← Temp
E ENDIF
Line B — Temp must store the first score before it is overwritten. With Score[2] stored, the original Score[1] is lost and the swap fails. It should be Temp ← Score[1].
Question 5
A DECLARE Found : INTEGER
B Found ← FALSE
C OUTPUT Found
Line A — A Found flag holds TRUE or FALSE, so its data type must be BOOLEAN, not INTEGER. It should be DECLARE Found : BOOLEAN.

Student with a class code? Join your class →