Finding Maximum, Minimum & Calculating Average

A current maximum or minimum must start at a value that is valid for the actual dataset. Guessing 9999 as a minimum fails if every input exceeds 9999; starting a maximum at zero fails for all-negative data.

Worked example

Read the first value, 12000. Set both Minimum and Maximum to 12000. The next value, 15000, changes Maximum only. A later 11000 changes Minimum only. The result is based on observations rather than a guessed limit.

INPUT Value
Minimum <- Value
Maximum <- Value
FOR i <- 2 TO 5
    INPUT Value
    IF Value < Minimum THEN
        Minimum <- Value
    ENDIF
    IF Value > Maximum THEN
        Maximum <- Value
    ENDIF
NEXT i

Trace before coding

For -6,-2,-9, the successive (minimum,maximum) pairs are (-6,-6), (-6,-2), (-9,-2). Equal values do not require changing either extreme. Test all-equal, all-negative and large values, not only convenient positive values.

The separate mean lesson combines total and count and handles an empty dataset.

AI Socratic Tutor

All-Access
Sign in or create an account. AI Tutor is an All-Access benefit.
Sign Up

Need guidance? Ask a question or use the hint below.

AI Socratic Tutor is an All-Access Benefit

Unlock step-by-step Socratic hints, algorithm trace table walkthroughs, and error diagnostics for every Cambridge exercise.

You're chatting with an AI tutor, not a person. AI can make mistakes, so double-check its answers.

Exam-Style Question: Complete Average and Min/Max Calculation

+35 XP

Assume each score is between 0 and 100 inclusive. Complete the algorithm to compute the average of 10 student scores and find the highest score:

PSEUDOCODE
Highest <- 0
Total <- 0
FOR i <- 1 TO 10
    INPUT Score
    Total <- Total + Score
    IF Score [Space 1] Highest THEN
        Highest <- Score
    ENDIF
NEXT i
Average <- Total [Space 2] [Space 3]
Word Bank / Available Cards (Drag into spaces or tap to place)

All-Access Required

Interactive exercises for Module 2 and beyond require an active plan.