How to get the overall average of the data received I have an arduino uno with two sensors. Voltage and current sensors. I need to get the average value of voltage and current each time the data is received. But i don't know how to add up the current and previous values and divide it to how many values that it has received. 

Can someone help me, please? I need it for my project

This is the code i have made

void setup(){
Serial.begin(9600);
}
void loop(){
    int n=5;
    float sum=0;
    float ave=0;
    for(int x=0;x&lt;n;x++){
        float volt=analogRead(A0);
        float voltage = map(volt,0,1023,0,2500);
        voltage/=100;
        Serial.print("Voltage: ");
        Serial.print(voltage,2);
       sum=sum+voltage;
       }
ave=sum/n;
Serial.print("Average: ");
Serial.print(average,2);
delay(3000);
}


But this only takes the average of 5 datas. I want to get the average of all data received.
void setup(){
Serial.begin(9600);
}
void loop(){
    static unsigned long count=0;
    static float sum=0;
    float ave=0;
    int volt=analogRead(A0);
    float voltage = map(volt,0,1023,0,2500) / 100.0;
    Serial.print("Voltage: ");
    Serial.print(voltage,2);
    sum=sum+voltage;
    count++;
    ave=sum/count;
    Serial.print("  Average: ");
    Serial.println(ave,2);
    delay(3000);
}


This runs quite a while. The average is restarted only with a Reset of your arduino.

Alternatively, you might want to learn about a moving average (aka low pass filter)