Totalling & Counting (Cambridge (CIE) O Level Computer Science)

Revision Note

Robert Hampton

Expertise

Computer Science Content Creator

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

FOR x ← 1 TO 20 [1]

INPUT Number

IF Number > 50

THEN

Total ← Total + 1 [1]

NEXT x

PRINT total [1]

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

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

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.