[2015-05-11] Challenge #214 [Easy] Calculating the standard deviation

I'm pretty much a beginner, have done some Java/C++ in the past for fun and forgotten probably 80% of what I used to know. Some of these 5-6 line answers make me feel pretty silly, but all in due time I guess.

#include <iostream>

include <sstream>

include <vector>

include <string>

include <math.h>

using namespace std;

double getAverage(vector<int> values); double getVariation(vector<int> values, double average);

int main() { vector<int> data; string input;

cout << "Please enter a list of positive integers: \n";
getline(cin, input);

stringstream strm(input);
int i;

while (strm >> i)
{
    data.push_back(i);

    if (strm.peek() == ' ')
        strm.ignore();
}

double average = getAverage(data);
double variation = getVariation(data, average);

cout << "Average: " << average << "\n";
cout << "Standard Variation: " << variation;

}

double getAverage(vector<int> values) { double total = 0;

for (int i : values)
    total += i;

return (total / values.size());

}

double getVariation(vector<int> values, double average) { double total = 0;

for (int i : values)
{
    double diffSq = pow((i-average), 2);
    total += diffSq;
}

double totalVar = total / values.size();

return sqrt(totalVar);

}

Outputs:

Please enter a list of positive integers:

5 6 11 13 19 20 25 26 28 37 Average: 19 Standard Variation: 9.77753

Please enter a list of positive integers: 37 81 86 91 97 108 109 112 112 114 115 117 121 123 141 Average: 104.267 Standard Variation: 23.2908

Please enter a list of positive integers: 266 344 375 399 409 433 436 440 449 476 502 504 530 584 587 Average: 448.933 Standard Variation: 83.6616

Please enter a list of positive integers: 809 816 833 849 851 961 976 1009 1069 1125 1161 1172 1178 1187 1208 1215 1229 12 41 1260 1373 Average: 1076.1 Standard Variation: 170.127

/r/dailyprogrammer Thread