combine functions and linker error??

I started a program that calculates an employee's weekly gross pay when the user inputs hours worked and hourly pay rate. With what I have so far, it compiles fine, but gives these errors:

on Dev-C++:
message: [Linker error] undefined reference to 'get_pay(float, float)'
Id returned 1 exit status
file: C:\Dev-Cpp\Programs\Makefile.win message: [Build Error][grossPay.exe] Error 1

on Visual Studio 2005:
1>------ Build started: Project: grossPay, Configuration: Debug Win32 ------
1>Linking...
1>grossPay.obj : error LNK2019: unresolved external symbol "void __cdecl get_pay(float,float)"

How do I resolve this linker error? And also, how would I add if/else statements for the following condition? If the employee's weekly gross pay is more than $200 (personal exemption), then the employee pays 12% federal tax and 5% state tax from his taxable income (gross pay - exemption). I'd also like to combine the functions I have so that taxable income, fed tax, and state tax are all calculated in the same function.

Here's what I have:

#include <cstdlib>
#include <iostream>

using namespace std;

void get_pay(float wage, float hours);
float calc_gross_pay(float wage, float hours);
float calc_net(float gross, float deduct);
void print_gross_pay(float);
void print_net(float);

int main(int argc, char *argv[])
{
float wage,hours,gross,deduct,sum;

get_pay(wage, hours);
gross = calc_gross_pay(wage, hours);
sum = calc_net(gross, deduct);
print_gross_pay(gross);
print_net(sum);

system("PAUSE");
return EXIT_SUCCESS;
return 0;
}

void get_pay(float& wage, float& hours)
{
cout << "Enter your hourly wage: ";
cin >> wage;
cout << "Enter your hours worked: ";
cin >> hours;
}

float calc_gross_pay(float wage, float hours)
{
return wage * hours;
}

float calc_net(float gross, float deduct)
{
return gross - deduct;
}

void print_gross_pay(float gross)
{
cout << "Your gross pay is: " << gross;
}

void print_net(float sum)
{
cout << "Your net pay is: " << sum;
}
I think your meant to pass the values to the function, if you create them inside the function you shouldn't add the wage and hours to the arguement list.

For your tax thing I'd say have a function called tax:
1
2
3
4
5
if (gross > 200) {
  // 12% tax calculation
}else{
  // 5% tax calculation
}
Last edited on
The prototype for get_pay() says it takes two floats, bu the definition says it takes two references to floats.

print_gross_pay() and print_net() can be made into a single function by taking one more parameter.

main() has code after a return.
Topic archived. No new replies allowed.