Simple Function question about non-running average

I am working off of the smoothing function provided by Arduino. The objective is to get and store the average of JUST the first ten readings off of the sensor. I do not want to keep averaging the subsequent readings. For some reason this is escaping me. What I am providing keeps averaging the values. (i’ve just included the pertinent parts of the code)

const int numReadings = 10;
int readings[numReadings];
int total = 0;
int average = 0;

int sweatPin=0;
int sweatVal=0;

void setup() {
  for (int thisReading =0; thisReading < numReadings; thisReading++){
    readings[thisReading] = 0;

void loop() {
  for(int index=0; index<numReadings; index++){
  total = total - readings[index];
  readings[index] = analogRead(sweatPin);
  total = total + readings[index];
  average = total/10;



Help me understand. It looks like this code takes ten readings, saves them and then divides the total by 10. Unless I'm misunderstanding something that's exactly what you said you wanted to do.

Oh, wait. This is in the loop function that gets called over and over. Move this code to the setup function so it will get executed only once. You can also pare this down a bit because it doesn't need to do the subtraction when the array is already zeroed.

Hope this helps and I'm not completely off base.