Static typecast error

I'm doing this void homework for class and I can't figure out how to fix my last single error.This is the code

#include <iostream> //for using cin and cout
#include <conio.h> //for using getch()

using namespace std;

void GetEmployees(int& NumEmployees)
{
cout << "How many employees are in the company? ";
cin >> NumEmployees;

while (NumEmployees < 1)
{
cout << "Invalid number\n";
cout << "Please enter a valid number: ";
cin >> NumEmployees;
}
}

void CalculateAbsences(int daysMissed, int& total)
{
total = 0;

cout << "Enter the absences for each employee? (enter negative to end)";
while (daysMissed > -1) //so absences is always above -1
{
cin >> daysMissed;
if (daysMissed > -1)
{
total = total + daysMissed; //keep adding until negative is entered

}
}
}

double CalculateAverage(int NumEmployees, int total)
{
double average = static_cast<double>(total)/NumEmployees;
return average;

}

void DisplayResults(double average, int NumEmployees)
{
cout << "The average is: " << average << endl;
cout << "The number of employees are " << NumEmployees << endl;

}

int main()
{
int employeeCount;
int daysAbsent;
int totalAbsences;

GetEmployees(employeeCount);

CalculateAbsences(employeeCount, totalAbsences);

CalculateAverage(employeeCount, totalAbsences);

DisplayResults(CalculateAverage, employeeCount);

getch();
return 0;
}


The error is 'DisplayResults' : cannot convert parameter 1 from 'double (__cdecl *)(int,int)' to 'double'

It's on void DisplayResults. I tried to remove the parameter variable but it became worse.
A function name without parenthesis is a pointer to that function. That's what the weird error means.

Basically you have two options:

1) (not recommended) Call the function in the DisplayResults line:

 
DisplayResults( CalculateAverage( employeeCount, totalAbsences ), employeeCount );


As you can see that's ugly and hard to follow, which is why I don't recommend it. A better solution is:

2) Catch the returned value from Calculate average in a variable, then pass it to DisplayResults:

1
2
3
double average = CalculateAverage( employeeCount, totalAbsences );

DisplayResults( average, employeeCount );
Thanks for the explanation. I finally cleaned it up
Topic archived. No new replies allowed.