Totalling & Counting (CIE IGCSE Computer Science)

Revision Note

Test Yourself
Becci Peters

Expertise

Computer Science

Totalling

  • Totalling involves adding up values, often in a loop
  • A total variable can be initialised to 0 and then updated within a loop, such as:

Pseudocode example:

total 0

for i 1 to 10

input num

total total + num

next i

output total

Python example:

total = 0

for i in range(1, 11):

num = int(input("Enter a number: "))

total += num

print("Total:", total)

Java example:

int total = 0;

Scanner scanner = new Scanner(System.in);

for (int i = 1; i <= 10; i++) {

System.out.print("Enter a number: ");

int num = scanner.nextInt();

total += num;

}

System.out.println("Total: " + total);

Visual Basic example:

Dim total As Integer = 0

For i As Integer = 1 To 10

Console.Write("Enter a number: ")

Dim num As Integer = Integer.Parse(Console.ReadLine())

total += num

Next i

Console.WriteLine("Total: " & total)

Counting

  • Counting involves keeping track of the number of times a particular event occurs
  • A count variable can be initialised to 0 and then updated within a loop, such as:

Pseudocode example:

count 0

for i 1 to 10

input num

if num > 5 then

ount count + 1

end if

next i

output count

Python example:

count = 0

for i in range(1, 11):

num = int(input("Enter a number: "))

if num > 5:

count += 1

print("Count:", count)

Java example:

int count = 0;

Scanner scanner = new Scanner(System.in);

for (int i = 1; i <= 10; i++) {

System.out.print("Enter a number: ");

int num = scanner.nextInt();

if (num > 5) {

count++;

}

}

System.out.println("Count: " + count);

Visual Basic example:

Dim count As Integer = 0

For i As Integer = 1 To 10

Console.Write("Enter a number: ")

Dim num As Integer = Integer.Parse(Console.ReadLine())

If num > 5 Then

count += 1

End If

Next i

Console.WriteLine("Count: " & count)

Worked example

Write an algorithm using pseudocode that:

  • Inputs 20 numbers
  • Outputs how many of these numbers are greater than 50

[3]

 

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?

Becci Peters

Author: Becci Peters

Becci has been a passionate Computing teacher for over 9 years, teaching Computing across the UK helping to engage, interest and develop confidence in the subject at all levels. Working as a Head of Department and then as an educational consultant, Becci has advised schools in England, where her role was to support and coach teachers to improve Computing teaching for all. Becci is also a senior examiner for multiple exam boards covering GCSE & A-level. She has worked as a lecturer at a university, lecturing trainee teachers for Computing.