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);
}