Ok I'm having problems with part of a project im working on, so i figure ill paste the problem section of code:
Ok so what this does is the user enters a number in the textbox, then an array is made of the length that the user entered, random values fill the array, then it takes the standard deviation of the array values.
The variables in the bolded spot are giving me the errors "Use of unassigned local variable" I dont know why that shows up for certain variables in only certain spots.
private void stddevButton_Click(object sender, System.EventArgs e)
{
displayBox.Items.Clear();
double ave,sum,mean,temp = 0;
int i,i2 = Convert.ToInt32(inputBox.Text);
int[] init = new int [i];
Random rand;
rand = new Random();
while(i>0)
{
mean = init[i-1];
mean = rand.Next(20);
ave += mean;
i--;
}
i = Convert.ToInt32(inputBox.Text);
while(i>0)
{
temp = init[i-1];
temp = temp - mean;
temp *= temp;
sum += temp;
i--;
}
sum = Math.Sqrt(sum);
displayBox.Items.Add(sum);
}
{
displayBox.Items.Clear();
double ave,sum,mean,temp = 0;
int i,i2 = Convert.ToInt32(inputBox.Text);
int[] init = new int [i];
Random rand;
rand = new Random();
while(i>0)
{
mean = init[i-1];
mean = rand.Next(20);
ave += mean;
i--;
}
i = Convert.ToInt32(inputBox.Text);
while(i>0)
{
temp = init[i-1];
temp = temp - mean;
temp *= temp;
sum += temp;
i--;
}
sum = Math.Sqrt(sum);
displayBox.Items.Add(sum);
}
The variables in the bolded spot are giving me the errors "Use of unassigned local variable" I dont know why that shows up for certain variables in only certain spots.


Comment