#include<iostream> // for cin and cout
#include<cmath> // for square root function sqrt()
using namespace std; // for cin and cout in <iostream>
//Constants **************************************************
float Val1 = 16; //Given Integer Value 1
float Val2 = 21; //Given Integer Value 2
float Val3 = 23; //Given Integer Value 3
float Val4 = 29; //Given Integer Value 4
double IntValMean = (Val1 + Val2 + Val3 +Val4)/4; //Compute Mean Value of the Integers
double RunTotal = 0.0; // Running Total for Summations
double Deviation = 0.0; // Calculated Standard Deviation
//Functions***************************************************
double Summation()
{
//Calculate the Summation for each individual integer
RunTotal = (Val1-IntValMean)*(Val1-IntValMean);
RunTotal = RunTotal + ((Val2-IntValMean)*(Val2-IntValMean));
cout << ((Val1-IntValMean)*(Val1-IntValMean)) << endl;
cout << ((Val2-IntValMean)*(Val2-IntValMean)) << endl;
cout << ((Val3-IntValMean)*(Val3-IntValMean)) << endl;
cout << ((Val4-IntValMean)*(Val4-IntValMean)) << endl;
RunTotal = RunTotal + ((Val3-IntValMean)*(Val3-IntValMean));
RunTotal = RunTotal + ((Val4-IntValMean)*(Val4-IntValMean));
return RunTotal;
}
double StdDeviation()
{
double PreSqrd = RunTotal/(4-1); //Summation/(n-1) as part of formula
double EvalDev = sqrt(PreSqrd); //Take the Square Root to finish std dev equation
Deviation = EvalDev;
return Deviation; //Evaluated Standard Devitation Equation
}
void ResulPrint(double Dev, double Mean) {
cout << "The Standard Deviation of the Integers " << Val1 << "," << Val2 << ",";
cout << Val3 << ", and " << Val4 << " is:" << endl << endl;
cout << Dev << endl <<endl;
cout << "and their mean value is:" << endl <<endl;
cout << IntValMean << endl;
}
// Main Function**********************************************
int main() {
// Call the Standard Deviation Function
Summation();
StdDeviation();
//Print Result + Mean Value to Screen
ResulPrint(Deviation,IntValMean);
//Program Wait for Termination
char exit_char; // Temporary for input
cout << "\nPress any key and <enter> to exit \n";
cin >> exit_char; //Wait for key response before exiting.
return 0;
}
Which of these is wrong? I don't get it, what -6.25?
39.0625
1.5625
0.5625
45.5625
The Standard Deviation of the Integers 16,21,23, and 29 is:
5.37742
and their mean value is:
22.25
Press any key and <enter> to exit