C++ deviation help

Mafi0So

Weaksauce
Joined
Dec 7, 2005
Messages
99
this is the best I could do and still something doesn't work right
the formula part for deviation

#include <iostream.h>
#include <math.h>

/*
Gives you mean and standard deviation of 4 numbers
*/

void Getdata ();
void Calculate ();
void MakeOutput ();
void main ();
void Calc ();
void MakeOut ();
float m,x1,x2,x3,x4,o;

void main()
{
Getdata();
Calculate();
MakeOutput();
Calc();
MakeOut();
}
void Getdata ()
{
cout<<" Enter First nubmer ";
cin>>x1;
cout<<" Enter Second number ";
cin>>x2;
cout<<" Enter Third nubmer ";
cin>>x3;
cout<<" Enter Forth number ";
cin>>x4;
Calculate ();
}
void Calculate ()
{
m=(x1+x2+x3+x4)*1/4; //this is how I got MEAN
MakeOutput ();
}
void MakeOutput ()
{
cout<<" Mean is ";
cout<<m; //m represents MEAN
Calc();
}
void Calc()
{
o = sqrt(pow(x1-m,2)+pow(x2-m,2)+pow(x3-m,2)+pow(x4-m,2)*1/3); //thats a formula for standard deviation, Square root of addition of every value minus mean squared and multiplied by 1/3.
MakeOut ();
}
void MakeOut ()
{
cout<<"Standard Deviation is ";
cout<<o;
}

6336e4c48fd253b7a6f552fa2579525b.png

62c241b9f368cfa8d1d37b0a53950a55.png

this is what I used as example, but we need to do N-1.

Looking for pointers!
 
I can't quite figure out what it is you mean to ask. What is it that you specifically need help with?

What does it mean "to do N-1"?

Why are you multiplying by 1/3 when N is 4? Shouldn't you be multiplying by 1/4, there? I think you'll need some brackets, either way; you're multiplying only the last term, not the sum of all the terms.
 
I just went through it for him, order of operations problem combined with integer arithmetic. (Not to mention the globals, daisy chained function calls, lack of namespace, etc etc) I thought that divide by 3 was funny too, but thats how it is suppose to be.

(Back to building my mips cross compiler)
 
Groovy.

Where's the unwanted integer math, tho?
 
1/4 in average, 1/3 in std deviation. -- now that I think about it it should automatically promote to float... it mattered some how when I was messing with it I believe, may have just been order of operations as I found that last.

... I was just double checking and noticed I installed my mips compiler over my native compiler... =(

Good night! ;o)
 
I'm a newbie, and I'm lost, need to get a freaking book
thats a third class and our professor doesn't do a lot of explanations
thnx for input. ;)
 
now that I think about it it should automatically promote to float...
Yeah; the way it's written here, it will... assuming we're getting the pow() that returns a double, and I think we will.

Why is dividing by 3 correct for the standard deviation expression, when N = 4?
 
Cause my calculators standard deviation function matches when you divide by n-1 ;o)

-- Just checked it again in visual studio only problem was the missing parenthesis on the std deviation question. (I'm surprised it compiled without change on it)
 
Seems wikipedia is showing an incorrect formula, it's been dicussed in the dicussion page, but hasnt been fixed yet. They even give a drawn out numeric example with the incorrect formula which I think is kinda funny. ;o)
 
Cause my calculators standard deviation function matches when you divide by n-1 ;o)
Oh, I see! So the expression Mafi0So had posted was wrong. I just assumed it was correct.
Seems wikipedia is showing an incorrect formula,
That should be no surprise. They're too concerned with The Simpsons and Pokemon to bother with stuff like, you know, math.
 
Seems wikipedia is showing an incorrect formula, it's been dicussed in the dicussion page, but hasnt been fixed yet. They even give a drawn out numeric example with the incorrect formula which I think is kinda funny. ;o)

1/N is for the variance of the sample itself
1/(N-1) is for the variance of the population the sample is from. (Also known as the unbiased variance). This is typically what you see since you are almost always looking at a sampling from a larger group when doing statistical analysis.

If the program is supposed to return the standard deviation of the sample, then 1/N is the correct formula to use. Otherwise, 1/(N-1) would be the way to go.
 
N <- stands for the number of numbers you are using to get mean, so I used 4, so that gives me 1/3, thats what I figured out...
 
wow... all I had to do is add a pair of parenthesis in the equation, and you told me bunch of bs
now I know a much simpler way to do the whole thing, but you could've helped me on that one...
 
I just went through it for him, order of operations problem combined with integer arithmetic. (Not to mention the globals, daisy chained function calls, lack of namespace, etc etc) I thought that divide by 3 was funny too, but thats how it is suppose to be.

(Back to building my mips cross compiler)


Cause my calculators standard deviation function matches when you divide by n-1 ;o)

-- Just checked it again in visual studio only problem was the missing parenthesis on the std deviation question. (I'm surprised it compiled without change on it)

...? (Your welcome) ;o)
 
wow... all I had to do is add a pair of parenthesis in the equation, and you told me bunch of bs
now I know a much simpler way to do the whole thing, but you could've helped me on that one...

Wow. Three or four people go out of their way to help you out, and that's how you decide to thank them? That's pretty indignant.
 
I must admit I could have been clearer though. (It was late, my main os drives died that week, I had tons of docs, terms, etc open while compiling there in linux, I'm not always clear to begin with, etc)
 
no I thanked them, but yeah I couldn't understand crap when I was doing it
I'm read the comments, and those guys are just dissing me :(
but it was our third class on c++ so its the best I could come up with
but I went over the comments and yes someone mentioned parenthesis... so my fault
 
wow, that all I have say
this guy really hates me :p

You're clueless. mikeblas has been nothing but helpful. I know the internet is an imperfect medium for expression however I can't possibly see how you could misconstrue anything said in this thread as "dissing".
 
Back
Top