|
A variable (integer) can be used to count values that satisfy a certain condition.
Remember counting always
starts from 0 so the value of the variable must be initialised to 0.
Example
20 marks are to be input.
How many of them are over 50?
We will use a variable
called 'counter' to store the number of marks over
50.
The pseudocode algorithm is..
counter = 0
|
| for
20 times do |
|
| |
input (mark) |
|
| |
if
the mark is over 50 then |
| |
|
add 1 to counter |
| |
end if |
|
| end do |
|
|
| output
(counter) |
|
|