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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!