Totalling & Counting (Cambridge (CIE) IGCSE Computer Science)

Revision Note

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Totalling & Counting

How do you use totalling in a program?

  • Totalling involves adding up values, often in a loop

  • A total variable is set to 0 at the beginning of the program and then updated within a loop, such as:

Pseudocode

Python

Total ← 0
FOR I ← 1 to 10
     INPUT Num
     TOTAL ← TOTAL + Num
NEXT I
OUTPUT Total
total = 0
for i in range(1, 11):
    num = int(input("Enter a number: "))
    total = total + num
print("Total:", total)

How do you use counting in a program?

  • Counting involves keeping track of the number of times a particular event occurs

  • A count variable is set to 0 and then updated within a loop, such as:

Pseudocode

Python

Count ← 0
FOR I ← 1 to 10
    INPUT Num
    IF Num > 5 
        THEN
            Count ← Count + 1
    ENDIF
NEXT I
OUTPUT Count
count = 0
for i in range(1, 11):
    num = int(input("Enter a number: "))
    if num > 5:
        count = count + 1
print("Count:", count)

Worked Example

Write an algorithm using pseudocode that:

  • Inputs 20 numbers

  • Outputs how many of these numbers are greater than 50

[3]

Answer

Count = 0
FOR x ← 1 TO 20  [1]
    INPUT Number
    IF Number > 50 
        THEN 
            Count ← Count + 1  [1]
NEXT x
PRINT Count [1]

Last updated:

You've read 0 of your 5 free revision notes this week

Sign up now. It’s free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.