I am on the verge of finishing this project but I cannot figure it out. I asked my professor but when he said "for the 2 functions, some or all of the parameters need to be passed by reference, so that the functions can affect the arguments being passed in." But that just confused me more. IF anyone has any tips I would appreciate it. I would rather not have someone just solve it but more of point me in the right direction as that is how learning is accomplished.
Tried rewriting the code a couple of times.
#include <iostream>
#include <cmath> //included for some pre-defined functions
using namespace std;
//function PROTOTYPES will go here
void getValues(double x1, double x2, double x3, double x4, double x5);
double calcMean(double x1, double x2, double x3, double x4, double x5);
double calcDev(double stDev, double mean, double x1, double x2, double x3, double x4, double x5);
void printResults(double mean, double stDev);
//DO NOT CHANGE ANYTHING IN THE MAIN FUNCTION!!!
int main()
{
//Defining variables to store the values, the mean and the standard deviation
double x1, x2, x3, x4, x5;
double mean, stDev;
// calling all the functions
getValues(x1, x2, x3, x4, x5); // asks and reads in the 5 values.
mean = calcMean(x1, x2, x3, x4, x5); //calculates the mean
calcDev(mean, stDev, x1, x2, x3, x4, x5); //calculates the standard deviation
printResults(mean, stDev); //displays the results
return 0;
}
//the function DEFINITIONS will go below
void getValues(double x1, double x2, double x3, double x4, double x5){
cout<<"Please enter 5 values: ";
cin>>x1;
cin>>x2;
cin>>x3;
cin>>x4;
cin>>x5;
}
double calcMean(double x1, double x2, double x3, double x4, double x5){
return (x1+x2+x3+x4+x5)/5;
}
double calcDev(double stDev, double mean, double x1, double x2, double x3, double x4, double x5){
return stDev=sqrt(((pow(x1-mean, 2)+pow(x2-mean, 2)+pow(x3-mean, 2)+pow(x4-mean, 2)+pow(x5-mean, 2))/5));
}
void printResults(double mean, double stDev){
std::cout<<"The mean of the 5 values is: "<<mean<<std::endl;
std::cout<<"The standard deviation of the 5 values is: "<<stDev<<std::endl;
}
If I type in 5 7 9 11 13 then the mean should be 9 with a standard deviation of about 2.8 if I am not mistaken.