Issues with running average for loop: Error message 'int[int]'

Hello,

I am trying to write a program where one aspect of it is writing a running average for loop. An error that keeps coming up is: invalid types 'int[int]' for array subscripts. The error appears on the line: sum = sum + value ;
Does anyone know how to fix this error? Or is there an alternate way to calculate a running average?
Thanks in advance.
/* Use a photoresistor (or photocell) to turn on an LED in the dark

  • More info and circuit schematic: How to use photocell with Arduino - Ardumotive Arduino Greek Playground*
    _ Dev: Michalis Vasilakis // Date: 8/6/2015 // www.ardumotive.com */_
    #include <BlynkSimpleRedBear_Duo.h>
    SYSTEM_MODE(MANUAL);
    //Variables
    void setup(){
  • //Constants*
    const int pResistor = A0; // Photoresistor at Arduino analog pin A0
    const int ledPin=1; // Led pin at Arduino pin D1
    pinMode(ledPin, OUTPUT); // Set lepPin - 1 pin as an output
    pinMode(pResistor, INPUT);// Set pResistor - A0 pin as an input (optional)
    Serial.begin(9600);
    long sum;
    int value; // Store value from photoresistor (0-1023)
    int threshold;
    int x;
    int avg;
    int len = sizeof(value);
    float average (long * value,int len); // assuming array is int.
  • sum = 0L ; // sum will be larger than an item, long for safety.*
  • for (int i = 0 ; i < len ; i++)*
  • {*
    _ sum = sum + value ;_
    * return ((float) sum) / len ; // average will be fractional, so float may be appropriate.*
    }}
    }}
    void loop(){
    * value = analogRead(pResistor);*
    * Serial.println(value);*

* //You can change value "25"*
* if (value < threshold){*
* digitalWrite(ledPin, HIGH); //Turn led on*
* }*
* else{*
* digitalWrite(ledPin, LOW); //Turn led off*
* }*
* delay(10); //Small delay*
}

float average (long * value,int len);  // assuming array is int.

Why do you have a function prototype in the middle of setup()?

  return  ((float) sum) / len ;  // average will be fractional, so float may be appropriate.

setup() does NOT return a value.

You need to look at how, and where, to define a function.

If you want to program a function that gets an array of integers and returns it's average then you should follow this code:

double Avg(int reads []){
  int sum = 0;
  for (int i = 0;i<sizeof(reads);i++){
    sum+=reads[i];
  }
  return sum / sizeof(reads);
}