Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

must compile write a program to read numbers using a while loop. The output of t

ID: 3635746 • Letter: M

Question

must compile
write a program to read numbers using a while loop. The output of the program should be the smallest number, the largest number, the sum of the numbers and the average of the numbers.

double x, smallest, largest, sum, average;
int n;
cin >> x;

n = 1;
// n is the number of values read so far

smallest = x;
// smallest is the smallest number read so far

largest = x;
// largest is the largest number read so far

sum = x;
// sum is the sum of all the numbers read so far

while ( cin >> x ) {
...

// n is the number of values read so far
// smallest is the smallest number read so far
// largest is the largest number read so far
// sum is the sum of all the numbers read so fars
}

// n is the number of values read
// smallest is the smallest number read
// largest is the largest number read
// sum is the sum of all the numbers read
// average is the average of all the numbers read

Explanation / Answer

#include #include using namespace std; int main() { double x, smallest, largest, sum, average; int n; cin >> x; n = 1; // n is the number of values read so far smallest = x; // smallest is the smallest number read so far largest = x; // largest is the largest number read so far sum = x; // sum is the sum of all the numbers read so far while ( cin >> x ) { n = n+1; // n is the number of values read so far if (x largest) largest = x; // largest is the largest number read so far sum = sum + x; // sum is the sum of all the numbers read so fars } average = sum/n; cout