error "void value not ignored as it ought to be "

Hello everyone,
I faced with this error "void value not ignored as it ought to be ".
Could you please help me to fix it?
Thanks in advance.
#include <iostream>
#include <math.h>

using namespace std;

void avg(int theArray[], int sizeofArray);

int main()
{
int numbers[5]={12,21,32,43,54};
int total=avg(numbers,5);
int cal_avg;
cal_avg=total/5;
cout<<"cal_avg"<<cal_avg<<endl;

return 0;
}


void avg(int theArray[], int sizeofArray)
{
int sum=0;

for (int i=0; i<sizeofArray; i++)
{
sum+=theArray[i];

}

}
The avg function won't do anything because it doesn't return any result. Likely, it should return 'sum'.

The avg function is declared to not return anything (it returns 'void'). Therefore, there is nothing to assign to variable total.
Topic archived. No new replies allowed.