Use totals and counts together
Accumulate a running total and count how many values contribute to it.
Section 8 · Programming
Exam scope and assessment notes
This sequence follows Cambridge IGCSE Computer Science 0984, 2026–2028 syllabus Version 4. It covers section 8.1 (Programming concepts) only. Pseudocode examples use the published Cambridge format; the separate 2029–2031 syllabus is not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers, a browser-based programming workspace and human subject-teacher review remain outstanding. Cambridge states that 0984 has the same 2026–2028 subject content as 0478, with 9–1 grading. In June and November, Cambridge lists 0984 in Administrative zone 3 and for centres in Oman and the UAE. Confirm availability for your centre and exam series with Cambridge International. The separately published 2029–2031 syllabus changes to Python 3 only and removes pseudocode; this 2026–2028 route does not cover those changes.
Before you begin
- Be comfortable following an ordered algorithm and tracing variable values. Each lesson introduces the Cambridge pseudocode form it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
What should Total usually start as before summing positive values?
What you will learn
- Initialise a total and counter
- Update both values for each item
- Calculate an average only when at least one value exists
A total and a count answer different questions
Total ← Total + Value accumulates the sum. Count ← Count + 1 records how many values have been processed.
Initialise both variables before the loop. Updating the total without the count makes an average impossible; updating the count without the total loses the sum.
Guard the average calculation
Average is Total / Count only when Count > 0. If no values were entered, report that no average is available instead of dividing by zero.
Keep input, update and final output in separate stages so a trace table can show exactly how each value contributes.
Pause and explain
What should a program do if Count is 0 before calculating an average?
Worked example
Process scores 6, 8 and 10. Find their total, count and average.
Show the worked solution
- Start Total ← 0 and Count ← 0.
- For each score, add it to Total and increase Count.
- After three scores, Total is 24, Count is 3, and Average is 8.
Answer Total = 24; Count = 3; Average = Total / Count = 8.
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
Three values 4, 7 and 9 are processed. Give final Total, Count and Average.
Give me a hint
Add all values, count each once, then divide.
Compare my reasoning
- Total is 4 + 7 + 9 = 20.
- Three values were processed.
- Average is 20 / 3 = 6.666…
Total = 20; Count = 3; Average = 6.666… (about 6.67).
Look for these in your work
- Total correct
- Count correct
- Mean calculated
Describe the three updates needed inside a loop to total 8 entered values.
Give me a hint
One value is processed per pass.
Compare my reasoning
- Read the next value.
- Add it to Total.
- Increase Count by one.
Read each value, add it to Total and increment Count, with both variables initialised before the loop.
Look for these in your work
- Input each pass
- Total updated
- Count updated
A class has no submitted scores. Explain what an average routine should output and why.
Give me a hint
Check whether any values contributed to the total.
Compare my reasoning
- Count remains 0.
- Total / Count would divide by zero.
- Display a no-scores message instead of a numeric average.
Report that no average is available because there are no scores and division by zero is invalid.
Look for these in your work
- Zero-count check
- Safe output
Common mistakes
- Initialising Total inside the loop
- Forgetting to increment Count
- Dividing by zero when no values are present
What can you explain now?
Why is Count needed when calculating an average?
Compare with the explanation
It records how many values are in the total
The mean is the total divided by the number of values.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
Why must the average be calculated after the values have been totalled and counted?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.