Write a program which repeatedly reads numbers until the user enters 0. Once 0 is entered, print out the total, count, and average of the numbers. Use an array to store all the numbers. Example of execution:
Enter a number: 4
Enter a number: 5
Enter a number: 9
Enter a number: 0
Total = 18, count = 3, average= 6
answer by using while,for and array if possible
#include <iostream>
using namespace std;
int main()
{
cout << "Input numbers.\n";
cout << "To finish entering input 0.\n";
int countEl = 0;
double sum = 0;
int element;
cin >> element;
while (element){
sum += element;
countEl++;
cin >> element;
};
cout << "Total = " << sum << endl;
cout << "Count = " << countEl << endl;
cout << "Average = " << double (sum / countEl) << endl;
return 0;
}