← IGCSE Computer Science Paper 2

Average: how it works

The average is the total of the values divided by how many values there are. It needs both a total and a count, can be a REAL, and is not allowed when the count is zero.

Understanding Average: how it works in IGCSE Computer Science Paper 2

What it does: The loop builds up a Total and a Count together. Both are needed before the average can be found. The average is the total of the values divided by how many values there are. The total is 15 and the count is 3. 15 / 3 = 5. Fifteen is only the total. An average can have a decimal part, for example 7 / 2 = 3.5, so REAL is the safe choice. Only divide when Count is greater than 0. The wrong option divides exactly when Count is zero.

Common mistakes: The average is the total divided by the count, not the other way round. It should be Average ← Total / Count. An average often has decimal places, so it can be a REAL. Declaring it as INTEGER is wrong. It should be DECLARE Average : REAL.

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 286–295) 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
How do you calculate the average of a set of values?
Total divided by CountTotal multiplied by Count
Matches
Average ← Total / 0
↓
The code divides by zero. The average must be divided by Count, the number of values, and Count must never be zero.
Applying
Meanings
Term
Average ← Total / Count
Meaning
The average is the total of the values divided by how many values there are. It needs both a total and a count, can be a REAL, and is not allowed when the count is zero.
Practice
DECLARE Average : REAL
Testing
Gaps
Average ← / Count
Check Answer
Spots
2Count ← 5
3Average ← Count / Total

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

The 'Woolly Mammoth' badge — Tundra Master, 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. How do you calculate the average of a set of values?
A. Total divided by Count ✓
B. Total multiplied by Count
The average is the total of the values divided by how many values there are.
2. Which two things must you know before you can work out an average?
A. The total and the count ✓
B. The maximum and the minimum
Average ← Total / Count needs both a total and a count. Maximum and minimum are not used.
3. Which line correctly calculates the average?
A. Average ← Total / Count ✓
B. Average ← Total + Count
Average uses division: Total / Count. Adding them gives a meaningless number.
4. The marks are 4, 5 and 6. What is the average?
A. 15
B. 5 ✓
The total is 15 and the count is 3. 15 / 3 = 5. Fifteen is only the total.
5. Which data type should the variable Average be declared as?
A. DECLARE Average : INTEGER
B. DECLARE Average : REAL ✓
An average can have a decimal part, for example 7 / 2 = 3.5, so REAL is the safe choice.

Match the Pairs

Average ← Total / Count → Works out the average by dividing the total of the values by how many values there are
IF Count > 0 THEN Average ← Total / Count ENDIF → Only calculates the average when there is at least one value, so it never divides by zero
The average needs both a total and a count, so both must be worked out before dividing → FOR Index ← 1 TO 5 Total ← Total + Mark[Index] Count ← Count + 1 NEXT Index
An average can be a REAL, so the variable that stores it should be declared as REAL → DECLARE Average : REAL
Average ← Total / 0 → The code divides by zero. The average must be divided by Count, the number of values, and Count must never be zero.
Average ← Total → The total has not been divided by the count, so this stores the total of the values instead of the average.

Key Term

Average ← Total / Count
The average is the total of the values divided by how many values there are. It needs both a total and a count, can be a REAL, and is not allowed when the count is zero.

Fill in the Blanks

1. Average ← Total / Count
Hint: Type the variable that holds the sum of all the values.
2. Average ← Total / Count
Hint: Type the arithmetic operator that divides the total by the count.
3. DECLARE Average : REAL
Hint: Type the data type that can store a decimal result.
4. IF Count > 0 THEN Average ← Total / Count ENDIF
Hint: Type the number the count must be greater than to avoid dividing by zero.
5. Average ← Total / Count OUTPUT "Average is ", Average
Hint: Type the variable that stores the calculated result, so it can be output.

Spot the Error

Question 1
A Total ← 150
B Count ← 5
C Average ← Count / Total
D OUTPUT Average
Line C — The average is the total divided by the count, not the other way round. It should be Average ← Total / Count.
Question 2
A DECLARE Average : INTEGER
B Average ← Total / Count
C OUTPUT Average
Line A — An average often has decimal places, so it can be a REAL. Declaring it as INTEGER is wrong. It should be DECLARE Average : REAL.
Question 3
A Total ← 0
B Count ← 5
C FOR i ← 1 TO Count
D Total ← Total + i
E NEXT i
F Average ← Total / Count
Line D — This adds the loop counter i, not the score stored in the array. It should be Total ← Total + Score[i].
Question 4
A Count ← 0
B Total ← 0
C IF Count = 0 THEN
D Average ← Total / Count
E ENDIF
Line C — The division must only happen when Count is not zero, because dividing by zero is not allowed. The test should be IF Count > 0 THEN.
Question 5
A INPUT Mark
B Total ← Total + 1
C Count ← Count + 1
D Average ← Total / Count
Line B — The total must add the value that was input, not 1. Adding 1 is what the count does. It should be Total ← Total + Mark.

Student with a class code? Join your class →