Passing Arrays to Funtions

so this is what i have so far, im basically supposed to have a user input 12 amounts of rainfall for every month of the year then calc the total, and average rainfall within the 2 functions. BUT i keep getting 2 compile errors, can one of you maybe spot my error or tell me what im doing incorrectly

#include <iostream>

using namespace std;

void getTotal(double total [], int arraySize );

void getAverage(double average[], int arraySize );

int main()
{
double total[12];
double average[12];
int arraySize=12;

for ( int i=0 ; i < arraySize ; i++)
{
cout<<"Enter the rainfall (in inches) for month #"<<i<<endl;
cin>>total[i];
average[i]=total[i];
}

getTotal (double total [], int arraySize );
getAverage (double average[], int arraySize );

return 0;
}

void getTotal(double total [], int arraySize )
{
double sum=0;

for ( int x = 0 ; x < arraySize ; x++ )

sum=sum+total[x];

cout<<"The total rainfall for the year is "<<sum<<" inches."<<endl;

}

void getAverage(double average[], int arraySize)
{
double sum=0;
double av=0;

for ( int y = 0 ; y < arraySize ; y++ )

sum=sum+average[y];

av=sum/12;

cout<<"The average rainfall for the year is "<<av<< " inches."<<endl;

}

Error E2188 lab7.cpp 25: Expression syntax in function main()
Error E2188 lab7.cpp 26: Expression syntax in function main()
Last edited on
you calling function wrongly..
1
2
getTotal (double total [], int arraySize );
getAverage (double average[], int arraySize );

that's wrong.... you need not tot pass datatypes to the functions when you calling them...
remove that double, int and [] operator..
Topic archived. No new replies allowed.