Question

Doing assignment for class. Getting this error message:

    1>------ Build started: Project: Mulvihill_Program_7, Configuration: Debug Win32 ------
    1>Mulvihill_Program_7.obj : error LNK2019: unresolved external symbol "double __cdecl calcGross(void)" (?calcGross@@YANXZ) referenced in function _main
    1>c:\users\pat\documents\visual studio 2012\Projects\Mulvihill_Program_7\Debug\Mulvihill_Program_7.exe : fatal error LNK1120: 1 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Here is the code:

#include<iostream>
using namespace std;

int getHoursWorked();
double getPayRate();
double calcGross();

int hoursWorked = 0;
double payRate = 0.0;
double grossPay = 0.0;
double OVERTIME = 1.5;
double overTimePayRate = 0.0;
double pay = 0.0;



int main()
{

    getHoursWorked();
    getPayRate();
    pay = calcGross();

    cout<<pay;
}

int getHoursWorked()
{
    cout<<"Enter the amount of hours worked ";
    cin>>hoursWorked;

    return(hoursWorked);
}

double getPayRate()
{
    cout<<"How much do you make an hour? ";
    cin>>payRate;

    return(payRate);

}

double calcGross(int hoursWorked, double payRate)
{
    if (payRate < 40)
    {
        grossPay = hoursWorked * payRate;
    }
    else
    {
        overTimePayRate = OVERTIME * payRate;
        grossPay = hoursWorked * overTimePayRate;
    }
    return(grossPay);
}

I know there's probably a lot more wrong with this code than just the error in terms of conventions, and stuff, but I'm new at this, and I'm just trying to understand the error message for now.

Était-ce utile?

La solution

The linker cannot find this function definition,

double calcGross();

because you define the function as such,

double calcGross(int hoursWorked, double payRate)

Should you remove the parameters so that the function declaration & definition are matched. Change your function declaration like this,

int getHoursWorked();
double getPayRate();
double calcGross(int hoursWorked, double payRate);

Then pass the value of hoursWorked & payRate when calling it in main()

Autres conseils

Your calcGross() definition has a different type signature from the one that is called in main(). main() is calling a calcGross() without any arguments which is a totally different function from the calcGross() with two arguments -- int and double.

Just add

double calcGross()
{
    // replace with your logic
    return 0.0;
}

to the code and you'll not get any linker errors. Or supply the required arguments to the calcGross(int, double) definition.

Refer to type signature in Wiki for additional details.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top