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>
using namespace std;
void deviation(double, double, double, double);
int main()
{
double num1, num2, num3, avg;
char choice;
do{
cout << "Enter 3 doubles: ";
cin >> num1 >> num2 >> num3;
avg = (num1+num2+num3)/3;
cout << "\nThe average is: " << avg;
deviation(num1, num2, num3, avg);
cout << "\nDo you wish to enter another set of data? (y|n)";
cin >> choice;
}while(choice != 'n' || choice != 'N');
cout << "Goodbye!";
return 0;
}
void deviation(double num1, double num2, double num3, double avg){
double sdev;
sdev = sqrt( (pow((num1-avg),2) + pow((num2-avg),2) + pow((num3-avg),2)
) / 3 );
cout << "\nThe standard deviation is: " << sdev;
}
|