# error C2664: 'average' : cannot convert parameter 1 from 'int' to 'int []'

This is a discussion on error C2664: 'average' : cannot convert parameter 1 from 'int' to 'int []' within the C++ Programming forums, part of the General Programming Boards category; I'm currently taking the introduction to C++ class. I'm currently ahead of my class so the teacher refuses to answer ...

1. ## error C2664: 'average' : cannot convert parameter 1 from 'int' to 'int []'

I'm currently taking the introduction to C++ class. I'm currently ahead of my class so the teacher refuses to answer my questions -_-. I've been reading through my book and looking through the web but I can't understand what my mistake is, can anyone give me hints as to what my mistake is?

Also, I know the code is sort of a mess, I've been messing around with it alot to try and figure out the mistake so there are a few variables and instructions that aren't useful, it's just that I couldn't get my function that calculates the average to work so I just programmed the instructions into the main.

I marked the line with the error with ==><== error here.

Code:
```#include <iostream>

using namespace std;

int carre(int x);
double average(int a[]);

int main()
{
int n,
i,
m,
entier[5];
double moyenne,
moyenne_carre,
sum = 0,
sum_carre = 0;

char check;

do {
cout << "\nVeuillez entrer 5 valeures entieres : " <<endl;

for ( m = 0 ; m <= 4 ; m++ )
cin >> entier[m];

/*for ( m = 0 ; m <= 4 ; m++)
sum += entier[m];

moyenne = sum / 5;*/

cout << "La moyenne des chiffres est :";
for ( n = 0 ; n <= 4 ; n++ )
===>         cout << average(entier[n]) << " ";      <===  error here

/*cout << "Les valeures au carre sont: ";

for ( i = 0 ; i <= 4 ; i++ )
cout << carre(entier[i]) << " ";

for ( m = 0 ; m <= 4 ; m++ )
sum_carre += carre(entier[m]);

moyenne_carre = sum_carre / 5;

cout << "La moyenne des chiffres au carre est:" << moyenne_carre << endl;
*/
cout << "\nEncore? (y/n) :";
cin >> check;

} while (check == 'y');

cin.sync();
cin.get();
}

int carre(int x)
{
return x * x;
}

double average(int a[])
{
int avg = 0, sum = 0, n, i = 0;

for (n = 0 ; n <= 4 ; n++)
{
sum += a[n];
i=i++;
}

avg = sum/i;

return avg;
}```

2. average() is a function that accepts an array of int. When you call it, you pass a single int. A single int is not an array of int. Each element in the array is an int.

Instead of "cout << average(entier[n])" you probably need to do "cout << average(entier)" - and not do that in a loop.

entier is an array of four integers. entier[n] is the n'th element of that array.

3. Originally Posted by grumpy
average() is a function that accepts an array of int. When you call it, you pass a single int. A single int is not an array of int. Each element in the array is an int.

Instead of "cout << average(entier[n])" you probably need to do "cout << average(entier)" - and not do that in a loop.

entier is an array of four integers. entier[n] is the n'th element of that array.
I love you. thanks alot.