# Answer to Question #16374 in C++ for Phillip

Question #16374

Write a program that takes as input three numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x1, x2, and x3, then the mean(average) is x=(x1+x2+x3)/3 and the standard deviation is :

Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation.

Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation.

Expert's answer

#include <iostream>

#include <cmath>

using namespace std;

float numberOne;

float numberTwo;

float numberThree;

float mean;

float standardDeviation;

float calulatemean(){

mean = (numberOne + numberTwo + numberThree) / 4;

return mean;

}

float calculatestandarddeviation(){

mean=calulatemean();

standardDeviation = sqrt((pow(numberOne-mean,2)) + (pow(numberTwo-mean,2)) +

(pow(numberThree-mean,2))/ 3);

return standardDeviation;

}

int main ()

{

cout << "Input your first number :" ;

cin >> numberOne;

cout << "Input your second number:" ;

cin >> numberTwo;

cout << "Input your third number :" ;

cin >> numberThree;

cout << "The mean is " << mean << " and the standard deviation is " << calculatestandarddeviation() << "."

<< endl;

int k;

cin>>k;

return 0;

}

#include <cmath>

using namespace std;

float numberOne;

float numberTwo;

float numberThree;

float mean;

float standardDeviation;

float calulatemean(){

mean = (numberOne + numberTwo + numberThree) / 4;

return mean;

}

float calculatestandarddeviation(){

mean=calulatemean();

standardDeviation = sqrt((pow(numberOne-mean,2)) + (pow(numberTwo-mean,2)) +

(pow(numberThree-mean,2))/ 3);

return standardDeviation;

}

int main ()

{

cout << "Input your first number :" ;

cin >> numberOne;

cout << "Input your second number:" ;

cin >> numberTwo;

cout << "Input your third number :" ;

cin >> numberThree;

cout << "The mean is " << mean << " and the standard deviation is " << calculatestandarddeviation() << "."

<< endl;

int k;

cin>>k;

return 0;

}

## Comments

## Leave a comment