StudyDeck

Other Standard Methods of a Solution

Exam code: 2210
Written by: Ashika|Reviewed by: Caroline Carroll|Updated 2 July 2026

Totalling & Counting

Totalling & Counting

What is totalling?

  • Totalling is keeping a running total of values entered into the algorithm

  • An example may be totalling a receipt for purchases made at a shop

  • In the example below, the total starts at 0 and adds up the user inputted value for each item in the list

Pseudocode

Total ← 0
FOR Count ← 1 TO ReceiptLength
    INPUT ItemValue
    Total ← Total + ItemValue
NEXT Count
OUTPUT Total

What is counting?

  • Counting is when a count is incremented or decremented by a fixed value, usually 1, each time it iterates

  • Counting keeps track of the number of times an action has been performed

  • Many algorithms use counting, including the linear search to track which element is currently being considered

  • In the example below, the count is incremented and each pass number is output until fifty outputs have been produced

Pseudocode

Count ← 0
DO
    OUTPUT “Pass number”, Count
    Count ← Count + 1 
UNTIL Count >= 50
  • In the example below, the count is decremented from fifty until the count reaches zero. An output is produced for each pass

Pseudocode

Count ← 50
DO
    OUTPUT “Pass number”, Count
    Count ← Count - 1
UNTIL Count <= 0

Maximum, Minimum & Average

Maximum, Minimum & Average

  • Finding the largest (max), smallest (min) and average (mean) values in a list are frequently used method in algorithms

  • Examples could include:

    • Calculating the maximum and minimum student grades or scores in a game

    • Calculating the average grade of students in a class test

  • In the example below, in a list of student test scores, the highest, lowest and average scores are calculated and displayed to the screen

Pseudocode

Total ← 0
Scores ← [25, 11, 84, 91, 27]

Highest ← max(Scores)
Lowest ← min(Scores)

# Loop through the scores in the list (indexing starts from 0)
FOR Count ← 0 TO LENGTH(Scores) - 1
    # Add score to total
    Total ← Total + Scores[Count]
NEXT Count

# Calculate average
Average ← Total / LENGTH(Scores)

OUTPUT "The highest score is:", Highest
OUTPUT "The lowest score is:", Lowest
OUTPUT "The average score is:", Average