Working out an average from a total and a count
After the loop ends, divide the total by the count to get the mean. Check that Count > 0 first, so the program never divides by zero.
Understanding Working out an average from a total and a count in IGCSE Computer Science Paper 2
What it does: Each pass of the loop adds the value to Total and adds 1 to Count, so both are ready for the average at the end. The division comes after ENDWHILE so it uses the final Total and Count, and it sits inside an IF so it never divides by 0. Dividing by zero is not allowed. When the user enters no values, Count stays at 0, so the program must not divide. 150 / 5 = 30. Multiplying would give 750, but an average is found by dividing.
Common mistakes: Count >= 0 is true when Count is 0, so the program would still divide by zero. The check must be IF Count > 0 THEN. The average is the total divided by the count, not the other way round. It should be Average <- Total / Count.
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 379–388) and word search (Modules 379–398).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
Average <- Total / CountFill in the Blanks
Spot the Error
Student with a class code? Join your class →