Learn in your language
Skip to content
IGCSE · Cambridge (CIE) · 0478

Total and count values

Use a running total and a separate counter to process a sequence of values accurately.

Cambridge IGCSE Computer Science 0478 · Algorithm design and problem-solving · 2026–2028 Version 6 · 7

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?

Put the idea to work

Worked example

For values 4, 7 and 2, find the final total and count.

Show the worked solution
  1. Start Total ← 0 and Count ← 0.
  2. For each value, add it to Total and add one to Count.
  3. 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.

1 · Guided

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
  1. Start at Total=0, Count=0.
  2. After 3 and 6: Total=9, Count=2.
  3. After 4: Total=13, Count=3.

Total 13; Count 3.

Look for these in your work

  • Correct sum
  • Correct item count
2 · Independent

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
  1. Mark is the score, not the number of students.
  2. Check whether Mark meets the pass condition.
  3. 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
3 · Transfer

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
  1. Add each paid fee to TotalPaid.
  2. Increment PayingMembers only when a fee was received.
  3. 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
Recall without your notes

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.

Keep learning Computer Science

Course scope and assessment

165 original lessons map the listed objectives across all 10 main topics in the 2026–2028 Version 6 syllabus, with worked explanations and guided, independent and transfer practice. This is mapped teaching coverage, not proof of full exam readiness. Three earlier starter lessons remain available but are not counted as syllabus-mapped teaching. Practical programming experience in an executable browser workspace, full timed-paper practice, human subject-teacher review and the separate 2029–2031 syllabus remain outstanding. Practice is self-checked and does not award an official Cambridge grade.

StudyForA · Learn with understanding

Original teaching content and links to official sources. Check your exam year and qualification before using a resource.