Question
Create statistics , in a sentinel-controlled loop: Write a program to read a list of non-negative numbers and then print out the largest integer, the
Create statistics, in a sentinel-controlled loop:
Write a program to read a list of non-negative numbers and then print out the largest integer, the smallest integer, and the average of all of the integers that were entered. The user indicates the end of the input by entering any negative sentinel value, and that value must not be used in finding the largest, smallest, and average values.
The average should be of type double so it is computed with a fractional part. Handle the case where the first value is the sentinel by printing an error message and not trying to calculate the average (which would cause a division by 0 runtime error).
If the user did not enter any 0 or positive integers, that is, if the first number they enter is negative, print this error message:
You did not enter any positive integers.
Otherwise print out the statistics this way, assuming the user entered 1 2 2 -1:
For the 3 numbers you entered the largest value = 1 the smallest value = 1 and the average is = 1.66666666666666667
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