Question
Q4: Highs and lows(Loop algorithms: Maximum/minimum) Instructions Today well carry on working through some common loop algorithms. Our second one will be finding both the
Q4: Highs and lows(Loop algorithms: Maximum/minimum)
Instructions
Today well carry on working through some common loop algorithms. Our second one will be finding both the maximum and minimum of a set of values.
Your task is to fix the code so that it does what is expected/described below.
Details
Input
The program reads in the following:
an integer values (unknown quantity, each on their own line)
followed by one empty line (empty string )
Hint: This input style should look familiar!
Processing
You are to find the maximum and minimum of the set of integers read in. To do this, you will make use of the following algorithms, which in this program will overlap:
Minimum value algorithm:
Read in a value (make sure to convert it to proper data type)
_Initialize minimum to this first value
_
Use while loop with looking for sentinel, each time through loop:
Convert the input value to proper data type
* _Decide if the value is less than the value held in **minimum**_ * _If it is, set **minimum** to this new value _ * Read in another value
Maximum value algorithm:
Read in a value (make sure to convert it to proper data type)
_Initialize maximum to this first value
_
Use while loop with looking for sentinel, each time through loop:
Convert the input value to proper data type
Decide if the input value is greater than the value held in maximum
_If it is, set maximum to this new value
_
Read in another value
Output
Output the max/min of the values (done for you).
Sample input/output:
Input | Output |
---|---|
3 1 4 7 5 | Maximum: 7 Minimum: 1 |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started