You are to write a program to read numbers using a while loop. The output of the
ID: 3640674 • Letter: Y
Question
You are to 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.Loop invariants can help you write loops. A loop invariant is a statement which is true before you start executing a loop and is true as you complete each iteration. Ideally you will pick invariants related to the output of the program.
As an aid to writing I have included some suggested loop invariants for the loop for this program:
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
PS: Please rate the answer #include #include using namespace std; // Function prototypes int getLowest(int [], int); int getHighest(int [], int); int getSum(int [], int); double getAverage(int [], int); const int ARRAYSIZE = 100; //array size int main() { int number[ARRAYSIZE]; int highest, lowest, sum; //values double avg; //avg value int count = 0,i; char cont = 'Y'; while(cont == 'Y'){ coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.