I'm trying to write a function that takes in an array of ints and the size of the array (another int) and return a double that is equal to the average of the array. Something is going wrong when I try to call the function in the main. Please help.
#include <cstdlib>
#include <iostream>
using namespace std;
double average(int array[], int s)
{int sum = 0;
int k;
for( int i = 0; i < s; i++)
{
sum = sum + array[i];
return sum/s;
}
}
int main()
{
int array = (78,90,56,99,88,68,92);
double k = average(array,7);
cout << k;
system("PAUSE");
return 0;
}
Here are the errors I get:
20 C:\Dev-Cpp\poi.cpp invalid conversion from `int' to `int*'
20 C:\Dev-Cpp\poi.cpp initializing argument 1 of `double average(int*, int)'