Abstract Write a program which reads in integers and prints the count, sum, and
ID: 3606751 • Letter: A
Question
Abstract Write a program which reads in integers and prints the count, sum, and average thus far. Description The program should print out a table header and then read in integers keeping a count of how many integers have been read and their sum. Then, the program should output a table row with the count, sum and average thus far. The program keeps reading in integers and printing results unil a value of -999 is read, at which time the program terminates. WARNING: it is possible the first integer read is-999 in which case only the table may be printed. Input Input to your program are integers, one at a time, fed in via input redirection. The file contents are random integers, one per line. Use the random number generator we created in class to create this input file of random numbers Output DO NOT PROMPT THE USER!! Prompting the user will mess up your ourput display (i.e. the table). Just read in an integer each time. The table header should have labels Count, Sum, Ave followed by a bar of '=" chars. The text 'Count. Sum, and'Ave' should be centered in field widths of 10, 20, and 20 separated by 2 spaces each respectively 102020 Do centering programmatically, do not hard code it. In other words don't just CountExplanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int sum = 0;
int count = 0;
int num;
double average;
cout << setfill('=') << setw(10) << "Count" << setw(20) << "Sum" << setw(20) << "Average" << endl;
while(true) {
cin >> num;
if(num == -999) {
break;
}
count++;
sum += num;
average = sum / (double)count;
cout << setfill(' ') << setw(10) << count << setw(20) << sum << setw(20) << average << endl;
}
return 0;
}