problem with for loop

I tried to write a program that will ask the user to choose the size of an array then enter the values then it should to calculate the sum then the average then calculate S. Everything is working but i still get zero for the sum.

char junk=' ';
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600); //set comunication speed to 9600.
Serial.println("This demo progrmm is to cal sum and product of an array");
Serial.println("");
Serial.flush(); //waits for transmission of outgoing serial data to complete.

}

void loop()
{
int n=8;
float x[n];
float sum;
int i;
float j;
float s;
float k;
Serial.println("Enter a total numer of data for n then Press ENTER");
while (Serial.available()==0); 
{
 n=Serial.parseFloat(); 
 while (Serial.available()>0) 
 {junk=Serial.read();} 
}

 Serial.print("n=");Serial.println(n,DEC);
 delay(2000);
for (i=0;i<n;i++)
{
  Serial.println("enter value for x tthen press ENTER");
  while (Serial.available()==0);
  {
    x[i]= Serial.parseFloat();
    while (Serial.available()>0) 
 {junk=Serial.read();} 
 Serial.println("values for array x");Serial.println(x[i],2);
  }
}
while (i==0);
{

 k= sum+ x[i];
 Serial.println("sum=");Serial.println(k,3);
  j=(k)/n;
 Serial.println("ave=");Serial.println(j,3);
}
s=sqrt((1/n-1)*k+x[i]*pow((i-j),2.0));
Serial.println("value for S");Serial.println(s,3);
delay(2000);
}
while (i==0);

Is that an extra semicolon there? Or did you want nothing to happen while i is zero and that block following it to only run once?

Or did you want nothing to happen while i is zero and that block following it to only run once?

I assume that Delta_G was just being facetious. Delta_G would know that if the variable i is ever zero, this would be an infinite loop and "that block following it" would never run at all.

"that block following it" only gets run (and only once) if the variable i is NOT zero.

vaj4088:
I assume that Delta_G was just being facetious.

Absolutely. It's obvious from the rest of the code and the intention that i wouldn't ever be zero at that point and that the OP intended that block to be the while loop.

Although, thinking more about it I think he wants to run while i is >=0 and not while it is ==0.

@OP
You really {need} to stop {inserting useless} {curly braces} in your code. The curly braces are for a purpose. Learn WHEN they are required, and when they are optional (but a good idea). Use them ONLY when needed (including the optional cases), but NOT when not needed.