Unable to open this exercise
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
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.
Independent Practice: Safe maximum and minimum
Read five integers, which may be negative or greater than 9999. Output the maximum and then the minimum. Do not assume arbitrary upper or lower limits.
Write a complete program. Read inputs in the stated order. Output only the requested results, one per line, without input prompts. Test with your own values before submitting.
Interactive exercises for Module 2 and beyond require an active plan.
Run code to inspect step-by-step variable trace states.