Totalling & Counting (Cambridge (CIE) IGCSE Computer Science)
Revision Note
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 |
---|---|
|
|
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 |
---|---|
|
|
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]
Last updated:
You've read 0 of your 10 free revision notes
Unlock more, it's free!
Did this page help you?