1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
#include <cmath>
void deviation(double& ave2);
void average(double& first, double& second, double& third, double& fourth, double& ave1);
void average2(double& first, double& second, double& third, double& fourth, double& ave1, double& ave2);
using namespace std;
int main()
{
double first, second, third, fourth;
double ave1, ave2;
cout << "Enter four numbers." << endl;
cin >> first;
cin >> second;
cin >> third;
cin >> fourth;
average(first, second, third, fourth, ave1);
average2(first, second, third, fourth, ave1, ave2);
deviation(ave2);
cout << ave2;
return 0;
}
void average(double& first, double& second, double& third, double& fourth, double& ave1)
{
ave1 = (first + second + third + fourth) / 4;
}
void average2(double& first, double& second, double& third, double& fourth, double& ave1, double& ave2)
{
ave2 = (first - ave1) + (second - ave1) + (third - ave1) + (fourth - ave1);
}
void deviation(double& ave2)
{
cout << "The standard deviation of this set is " << sqrt(ave2) << ".";
}
|