invalid types `int[int]' for array subscript

I am calling this function and receiving the error "invalid types `int[int]' for array subscript"

1
2
3
4
5
6
7
8
9
float Average(int grades)
{
      float total=0;
      for (int a=0;a<g;a++)
      {
          total=total+grades[a];
      }
      return total/g;
}

The error is occurring on line 6: total=total+grades[a];

Can someone explain what the error means and how I might be able to correct it?

Thanks for any help.
grades is an int. Just one int. We know this because it's in the function prototype at the top:
float Average(int grades)

grades is not an array, so we cannot treat it like an array, so grades[a] cannot work.
Last edited on
for (int a=0;a<g;a++) did you forget to declare your
g
? or you just use g for
grades
? grades is a prototype that you declare for your function. it doesnt make any sense to call it and use it for array.
Thank you both for your help. I should have posted the entire code I was using. I passed in grades which was previously declared as an array. I didn't realize I had to re-declare it as such again with the function. Chalk another one up to a newbie making a bonehead mistake.

Thanks again guys.
Topic archived. No new replies allowed.