Make a C ++ program that calculates the sum, mean of a series of numbers.
Example:
-Numbers: 10, 12, 10, 14
-The sum is 46,
-the mean is 11.5
#include <iostream>
#include <sstream>
using namespace std;
int main() {
int x, sum=0, n=0;
char ch;
string str;
cout << "Numbers: ";
getline(cin, str);
istringstream iss(str);
while (iss) {
if (iss >> x) {
sum += x;
n++;
}
iss >> ch;
}
cout << "The sum is " << sum << endl;
double mean = static_cast<double>(sum) / n;
cout << "The mean is " << mean << endl;
}
Comments
Leave a comment