Standard deviation calculation code not working as intended
Hello! I am currently trying to code a button that will calculate the mean and standard deviation from a set of 10 data values, however, my after coding my button calculates the mean properly but for whatever reason does not calculate the standard deviation and instead puts the value of the mean in its position instead.
I will leave a copy of the code below.
8 Replies
private void button1_Click(object sender, EventArgs e)
{
int y1;
y1 = (x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10) / 10;
lblMeanText.Text = y1.ToString();
double sumsquared = Math.Pow(x1 - y1, 2) + Math.Pow(x2 - y1, 2) + Math.Pow(x3 - y1, 2) + Math.Pow(x4 - y1, 2) + Math.Pow(x5 - y1, 2) + Math.Pow(x6 - y1, 2) + Math.Pow(x7 - y1, 2) + Math.Pow(x8 - y1, 2) + Math.Pow(x9 - y1, 2) + Math.Pow(x10 - y1, 2);
lblStdDeviation.Text = y1.ToString();
double standarddeviation = Math.Sqrt(sumsquared / 10);
}
lblStdDeviation.Text = y1.ToString();
You set the text of both lblMeanText
and lblStdDeviationText
to y1
variable
So of course they will be the sameoh haha
let me quickly fix that
Also, $code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/oh I see thank you!
I
Does the calculation for the standard deviation look correct?
Seems so
it seems to be working now, I appreciate the assistance!
I will close the post shortly