-
Help!
I need to write a program to calculate the mean and standard deviation of a set of data. Need to use functions ReadData, PrintData,CalcMean,CalcStanDev.....I have no idea what I'm doing. I'm barely beginning to grasp loops. CodeGuru's been good to me in the past, please help me out?
-
Re: Help!
Write ReadData and PrintData first. After that, it's just equations.
-
Re: Help!
The equations are whats killing me, I never learned standard deviation
-
Re: Help!
Well, standard deviation is just the square root of the variance, and the variance isn't any more difficult to compute than the mean:
http://en.wikipedia.org/wiki/Computa...r_the_variance
-
Re: Help!
aye, im looking at the equation now. I have no idea what it means, maybe my brother can get through to me
-
Re: Help!
This might be a more useful link:
http://en.wikipedia.org/wiki/Algorit...ating_variance
While all the caveats and alternatives are interesting, for your purposes the naive algorithm should be good enough. Note the relationship to the equation at the top of the previous link.
-
Re: Help!
Thanks I'm gonna run with this for a little and see where I can, I'll probably be back to check my coding
-
Re: Help!
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
ReadData
PrintData
int calc (float a, float b, float c, float d, float e, float sum, float mean,float sd);
float a, b, c, d, e, mean=0.0, avg=0.0;
float sd=0.0;
calc (a, b, c, d, e, &sum,&avg, &sd);
print("Mean=", mean);
print("Standard Deviation=", sd);
getchar();
return 0;
}
calc (float a, float b, float c, float d, float e, float sum float mean, float sd)
{
float Calc=0.0;
*sum = a+b+c+d+e;
*avg = *sum / 5.0;
Calc += ( a - avg) * ( a - avg);
Calc += ( b - avg) * ( b - avg);
Calc += ( c - avg) * ( c - avg);
Calc += ( d - avg) * ( d - avg);
Calc += ( e - avg) * ( e - avg);
sd = sqrt((double)Calc/5.0);
}
system("PAUSE");
return EXIT_SUCCESS;
}
-
Re: Help!
this is what I got but it isn't compiling
-
Re: Help!
Code:
int calc (float a, float b, float c, float d, float e, float sum, float mean,float sd);
This is inside your main function, it should be outside.
What is this doing there ?
Code:
system("PAUSE");
return EXIT_SUCCESS;
this code belongs in your main , not outside it..
sum is not a pointer.
Also, for posting code use code tags
-
Re: Help!
Thank you, as dumb as I feel thats the kind of help I need. I never should have taken Honors Computer Programming as a freshman but my teacher has been horribly nice to me considering and I'm just trying to make it through at least one of these 2 assignments that are due. Thanks. This is what I've got, still working though but any more advice in the mean time is greatly appreciated.
Code:
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
int calc (float a, float b, float c, float d, float e, float sum, float mean,float sd);
int main(int argc, char *argv[])
{
float a, b, c, d, e, mean=0.0, avg=0.0;
float sd=0.0;
CalcMean ((a+b+c+d+e)/5) ;
print("Mean=", mean);
print("Standard Deviation=", sd);
getchar();
return 0;
}
calc (float a, float b, float c, float d, float e, float sum float mean, float sd)
{
float Calc=0.0;
*sum = a+b+c+d+e;
*avg = *sum / 5.0;
Calc += ( a - avg) * ( a - avg);
Calc += ( b - avg) * ( b - avg);
Calc += ( c - avg) * ( c - avg);
Calc += ( d - avg) * ( d - avg);
Calc += ( e - avg) * ( e - avg);
sd = sqrt((double)Calc/5.0);
system("PAUSE");
return EXIT_SUCCESS;
}
-
Re: Help!
Idk if this code is salvageable. I have put together working programs before,its just been a while and I missed some chapters that obviously would have been helpful. I tried taking a shortcut on this one since I procrastinated for so long, hopefully I'll get it worked out, thanks anyway.
-
Re: Help!
Well, you were told to use functions called CalcMean and CalcStanDev rather than a single calc() function, so that's one change you can make immediately.
The first thing you need to figure out is how you're going to handle the data set. Right now, you have 5 float variables, which means you can't handle more than 5 values. Are you guaranteed you'll only get 5 values, or are you supposed to handle an arbitrary number? Will input be terminated after a specific count, or after a delimiting number is observed? Are you going to store all the inputs in memory, or process them "on the fly" with no storage? These are important details to worry about before you ever concern yourself with the equations.