← IGCSE Computer Science Paper 2

Totalling in Cambridge pseudocode

Adds each new Number to the running Total every time the loop repeats. Set Total ← 0 before the loop so the total starts from zero.

Understanding Totalling in Cambridge pseudocode in IGCSE Computer Science Paper 2

What it does: DECLARE names the variable Total and gives it the INTEGER data type so it can store whole-number sums. The FOR loop visits each array position in turn and adds that element to Total, so every mark is included. A declared variable has no guaranteed starting value in pseudocode. You must initialise Total to 0 yourself so the running total starts from zero. Total goes 0, then 4, then 11, then 20. The final total is the sum of all the values: 4 + 7 + 9 = 20. 9 would be the last value only, which is what happens if you write Total ← Number.

Common mistakes: A FOR loop uses TO to give its end value, not UNTIL. It should be FOR Count ← 1 TO 5. A DECLARE statement needs a colon between the variable name and its data type. It should be DECLARE Total : INTEGER.

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 275–285) and word search (Modules 275–295).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which line correctly adds Number to the running total?
Total ← Total + NumberTotal ← Number
Matches
FOR Count ← 1 TO 5 INPUT Number Total ← 0 Total ← Total + Number NEXT Count
↓
Total ← 0 is inside the loop, so the total is reset to zero on every repeat and only the last number is kept.
Applying
Meanings
Term
Total ← Total + Number
Meaning
Adds each new Number to the running Total every time the loop repeats. Set Total ← 0 before the loop so the total starts from zero.
Practice
DECLARE Total : INTEGER
Testing
Gaps
DECLARE Total :
Check Answer
Spots
2Total ← 0
3FOR Count ← 1 UNTIL 5

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

The 'Kangaroo Rat' badge — Speed Typer, 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. Which line correctly adds Number to the running total?
A. Total ← Number
B. Total ← Total + Number ✓
Total ← Total + Number takes the old total, adds the new Number and stores the result back in Total. Total ← Number would just overwrite the total each time.
2. Where should Total ← 0 be placed in a totalling algorithm?
A. Inside the loop, before the addition
B. Before the loop starts ✓
Total must be set to 0 once, before the loop. If it is inside the loop, it resets to 0 on every repeat and the running total is lost.
3. Which declaration is correct for a variable that stores a whole-number total?
A. DECLARE Total : INTEGER ✓
B. DECLARE Total ← INTEGER
Cambridge pseudocode declares a variable with DECLARE name : TYPE. A colon is used, not the assignment arrow.
4. What happens if you forget to set Total ← 0 before the loop?
A. The total may start from an unknown value, so the answer can be wrong ✓
B. The total automatically starts at 0 so nothing goes wrong
A declared variable has no guaranteed starting value in pseudocode. You must initialise Total to 0 yourself so the running total starts from zero.
5. Which loop correctly totals 5 numbers typed in by the user?
A. FOR Count ← 1 TO 5 INPUT Number Total ← Total + Number NEXT Count ✓
B. FOR Count ← 1 TO 5 INPUT Number Total ← Number NEXT Count
Each time round the loop, the new Number must be added to Total. Without + Total, the previous values are thrown away.

Match the Pairs

Total ← 0 → Sets the running total to zero before the loop starts
Total ← Total + Number → Adds the new Number to the running total each time the loop repeats
Declare an integer variable to hold the running total → DECLARE Total : INTEGER
Total every element in an array called Marks with 5 items → FOR Index ← 1 TO 5 Total ← Total + Marks[Index] NEXT Index
FOR Count ← 1 TO 5 INPUT Number Total ← 0 Total ← Total + Number NEXT Count → Total ← 0 is inside the loop, so the total is reset to zero on every repeat and only the last number is kept.
Total ← 0 FOR Count ← 1 TO 5 INPUT Number Total ← Number NEXT Count → Total ← Number replaces the total instead of adding to it, so the earlier values are lost.

Key Term

Total ← Total + Number
Adds each new Number to the running Total every time the loop repeats. Set Total ← 0 before the loop so the total starts from zero.

Fill in the Blanks

1. DECLARE Total : INTEGER
Hint: Type the data type used to store whole numbers.
2. DECLARE Total : INTEGER Total ← 0 FOR Count ← 1 TO 5
Hint: Type the value the running total must start from before the loop.
3. FOR Count ← 1 TO 5 INPUT Number Total ← Total + Number
Hint: Type the variable that holds the value just entered.
4. FOR Index ← 1 TO 10 Total ← Total + Scores[Index] NEXT Index
Hint: Type the loop counter that picks each array element.
5. FOR Count ← 1 TO 5 Total ← Total + Number NEXT Count
Hint: Type the variable that holds the running total so far.

Spot the Error

Question 1
A DECLARE Total : INTEGER
B Total ← 0
C FOR Count ← 1 UNTIL 5
D INPUT Number
E Total ← Total + Number
F NEXT Count
Line C — A FOR loop uses TO to give its end value, not UNTIL. It should be FOR Count ← 1 TO 5.
Question 2
A DECLARE Total INTEGER
B Total ← 0
C FOR Count ← 1 TO 5
D INPUT Number
E Total ← Total + Number
F NEXT Count
Line A — A DECLARE statement needs a colon between the variable name and its data type. It should be DECLARE Total : INTEGER.
Question 3
A DECLARE Total : STRING
B Total ← 0
C FOR Count ← 1 TO 4
D INPUT Price
E Total ← Total + Price
F NEXT Count
Line A — A total is a number that is added to, so it cannot be a STRING. Prices with decimals need REAL, so it should be DECLARE Total : REAL.
Question 4
A Total ← 0
B FOR Index ← 1 TO 5
C Total ← Total + Marks[Count]
D NEXT Index
E OUTPUT Total
Line C — The loop counter is Index, so the array must be read with Marks[Index]. Count does not exist in this program, so it should be Total ← Total + Marks[Index].
Question 5
A DECLARE Total : INTEGER
B Total ← 1
C FOR Count ← 1 TO 10
D INPUT Number
E Total ← Total + Number
F NEXT Count
Line B — The running total must start at 0 before the loop. Starting at 1 makes the final total 1 too big. It should be Total ← 0.

Student with a class code? Join your class →