Total and count values
Use a running total and a separate counter to process a sequence of values accurately.
This sequence follows Cambridge IGCSE Computer Science 0478, 2026–2028 syllabus Version 6. It covers subject content Topic 7 only. The separately published 2029–2031 syllabus is not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers and human subject-teacher review remain outstanding.
Before you begin
- No programming language is required. Be comfortable with place value and multiplication; each lesson introduces the computer-science notation it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
If no values have been processed, what should a running sum start at?
What you will learn
- Initialise a total and counter
- Update them once per valid item
- Explain the difference between total and count
Totals add values; counts add one per item
A running total stores the sum of values processed so far. Initialise it to zero before the loop, then add each valid value once.
Apply and check the rule
A counter records how many items have been processed, so it usually increases by one per valid item. A total and a count answer different questions: sum gives combined quantity; count gives number of entries.
Pause and explain
For values 8 and 5, what are Total and Count after both are processed?
Worked example
For values 4, 7 and 2, find the final total and count.
Show the worked solution
- Start Total ← 0 and Count ← 0.
- For each value, add it to Total and add one to Count.
- After three values, Total=13 and Count=3.
Answer Total 13; Count 3.
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.
Process 3, 6, 4 with a running total and counter. Give the final values.
Give me a hint
Add each number to the total and one to the count.
Compare my reasoning
- Start at Total=0, Count=0.
- After 3 and 6: Total=9, Count=2.
- After 4: Total=13, Count=3.
Total 13; Count 3.
Look for these in your work
- Correct sum
- Correct item count
An algorithm sets Count ← Count + Mark for every student. What is wrong if the aim is to count students who passed?
Give me a hint
The counter should change by one when the condition is met.
Compare my reasoning
- Mark is the score, not the number of students.
- Check whether Mark meets the pass condition.
- Increase Count by one only for a pass.
The algorithm adds the score rather than counting a pupil. If Mark >= PassMark, use Count ← Count + 1.
Look for these in your work
- Variable role
- Condition
- Increment
A club totals membership fees but includes one unpaid member as zero. Explain how the algorithm can keep the money total and member count meaningful.
Give me a hint
Decide whether to count all members or paying members, and make the definition explicit.
Compare my reasoning
- Add each paid fee to TotalPaid.
- Increment PayingMembers only when a fee was received.
- If total membership is also needed, maintain a separate AllMembers count.
Keep separate counters: increment AllMembers for every member and PayingMembers only when payment is recorded. Add actual fees to TotalPaid. This avoids mixing different measures.
Look for these in your work
- Total definition
- Paying count
- Separate population count
Common mistakes
- Initialising a total to one when no values have been processed
- Adding the value to the count instead of adding one
What can you explain now?
What does a counter normally add for each valid item?
Compare with the explanation
One
The counter measures how many items have been handled.
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
How does a running total differ from a counter?
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.