payroll calculator

I'm trying to get my payroll calculator to show the regular and overtime hours but after you enter hours worked it asks enter Y to rerun. I'm trying my hardest to understand functions but obviously there is something wrong with the code. Could someone PLEASE HELP me with this? It would be greatly appreciated:)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <iomanip>

using namespace std; 

const double HOURLYPAY=10.50;

void DisplayPay (int hours, double RegPay, double OverTPay, double DOTPay, double Pay, const double HOURLYPAY, double OT, double DTime, double NetPay);

void DisplayDeductions(double Taxes, double CPP, double EI, double UD, double Money, double NetPay);

int main() 
{ 
	int hours=0;

	char repeat = 'y';
	
	//user instructions
	cout<<"This program will calculate your pay for how many"<<endl;
	cout<<"hours you have worked. You will recieve time-and-a-half"<<endl;
	cout<<"for the first 5 hours of overtime, and double-time"<<endl;
	cout<<"pay for the rest of your overtime. Deductions will also"<<endl;
	cout<<"be calculated."<<endl<<endl;

	do//do-while loop
	{
		//input
		cout<<"Please enter the number of hours you have worked: ";
		cin>>hours;

		void DisplayPay (int hours, double RegPay, double OverTPay, double Pay, const double HOURLYPAY, double OT, double DTime);

		void DisplayDeductions(double &Taxes, double &CPP, double &EI, double &UD, double &Money, double &NetPay);

		//rerun the program
		cout<<"Enter y or Y to rerun the program, anything else to quit ";
		cin>>repeat;

		}while (repeat=='y'||repeat=='Y');//end do-while

	
	return 0;
}//end main


void DisplayPay (int hours, double RegPay, double OverTPay, double DOTPay, double Pay, const double HOURLYPAY, double OT, double DTime, double NetPay)
{
	if(40<=hours)//if hours are less than or equal to 40
	{
		Pay=hours*HOURLYPAY;
		NetPay=Pay;
	}

	else if(40<hours<=45)//hours are between 40 and 45
	{
		Pay=(HOURLYPAY*40);
		OT=(hours-40);
		OverTPay=(OT*15.75);
		NetPay=(40*HOURLYPAY)+(OverTPay);
	}

	else if(45<hours)//hours are greater than 45
	{
		Pay=(HOURLYPAY*40);
		DTime= (hours-45);
		OverTPay=(5*15.75)+(DTime*21.);
		NetPay=(DTime*21)+(5*15.75)+(40*HOURLYPAY);
	}
	cout<<"The number of hours you have worked are: "<<hours<<endl<<endl;
	cout<<"Regular pay: $"<<Pay<<endl;
	cout<<"Overtime pay: $"<<OverTPay<<endl<<endl;
	cout<<"Net pay: $"<<NetPay<<endl<<endl;

	cout<<"\n";
}

void DisplayDeductions(double Taxes, double CPP, double EI, double UD, double Money, double NetPay)
{
	Taxes=NetPay*0.31;
	CPP=NetPay*0.024;
	EI=NetPay*0.019;
	UD=NetPay*0.004;
	Money=NetPay-Taxes-CPP-EI-UD;

	cout<<"Here are your deductions: "<<endl<<endl;
	cout<<"Taxes: $"<<Taxes<<endl;
	cout<<"CPP: $"<<CPP<<endl;
	cout<<"EI: $"<<EI<<endl;
	cout<<"Union Dues: $"<<UD<<endl;
}
Line 31: This is not how you call function.
Look:
1
2
3
4
5
6
7
8
void foo(int bar); //This is function declaration. It tells compiler that there is such function somewhere

void foo(int bar)
{
    //This is function definition. It contains all statements which will be executed.
}

foo(baz);//This is function call. It executes function. 
Ok so lines 31 and 33 should look like

1
2
3
void DisplayPay (hours, RegPay, OverTPay, Pay, HOURLYPAY, OT, DTime);

void DisplayDeductions(Taxes, CPP, EI, UD, Money, NetPay);
yes, something like that
Alright that makes a lot more sense. But with what I did is I removed the void in front and I'm getting errors along the RegPay, OverTPay, ect, ect...

They are apparently all undefined except for hours and HOURLYPAY as these are defined in main().
Last edited on
Well, you are never defined them, so...
So what your saying is I need to define them on the top as well as in the functions?
Yes.
does this look right?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <iomanip>

using namespace std; 

const double HOURLYPAY=10.50;
double RegPay, OverTPay, DOTPay, Pay, OT, DTime, NetPay;
double Taxes, CPP, EI, UD;

void DisplayPay (int hours, double RegPay, double OverTPay, double DOTPay, double Pay, const double HOURLYPAY, double OT, double DTime, double NetPay);

void DisplayDeductions(double Taxes, double CPP, double EI, double UD, double Money, double NetPay);

int main() 
{ 
	int hours=0;

	char repeat = 'y';
	
	//user instructions
	cout<<"This program will calculate your pay for how many"<<endl;
	cout<<"hours you have worked. You will recieve time-and-a-half"<<endl;
	cout<<"for the first 5 hours of overtime, and double-time"<<endl;
	cout<<"pay for the rest of your overtime. Deductions will also"<<endl;
	cout<<"be calculated."<<endl<<endl;

	do//do-while loop
	{
		//input
		cout<<"Please enter the number of hours you have worked: ";
		cin>>hours;

		DisplayPay (hours, RegPay, OverTPay, Pay, HOURLYPAY, OT, DTime);

		DisplayDeductions(Taxes, CPP, EI, UD, NetPay);

		//rerun the program
		cout<<"Enter y or Y to rerun the program, anything else to quit ";
		cin>>repeat;

		}while (repeat=='y'||repeat=='Y');//end do-while

	
	return 0;
}//end main


void DisplayPay (int hours, double RegPay, double OverTPay, double DOTPay, double Pay, const double HOURLYPAY, double OT, double DTime, double NetPay)
{
	if(40<=hours)//if hours are less than or equal to 40
	{
		Pay=hours*HOURLYPAY;
		NetPay=Pay;
	}

	else if(40<hours<=45)//hours are between 40 and 45
	{
		Pay=(HOURLYPAY*40);
		OT=(hours-40);
		OverTPay=(OT*15.75);
		NetPay=(40*HOURLYPAY)+(OverTPay);
	}

	else if(45<hours)//hours are greater than 45
	{
		Pay=(HOURLYPAY*40);
		DTime= (hours-45);
		OverTPay=(5*15.75)+(DTime*21.);
		NetPay=(DTime*21)+(5*15.75)+(40*HOURLYPAY);
	}
	cout<<"The number of hours you have worked are: "<<hours<<endl<<endl;
	cout<<"Regular pay: $"<<Pay<<endl;
	cout<<"Overtime pay: $"<<OverTPay<<endl<<endl;
	cout<<"Net pay: $"<<NetPay<<endl<<endl;

	cout<<"\n";
}

void DisplayDeductions(double Taxes, double CPP, double EI, double UD, double Money, double NetPay)
{
	Taxes=NetPay*0.31;
	CPP=NetPay*0.024;
	EI=NetPay*0.019;
	UD=NetPay*0.004;
	Money=NetPay-Taxes-CPP-EI-UD;

	cout<<"Here are your deductions: "<<endl<<endl;
	cout<<"Taxes: $"<<Taxes<<endl;
	cout<<"CPP: $"<<CPP<<endl;
	cout<<"EI: $"<<EI<<endl;
	cout<<"Union Dues: $"<<UD<<endl;
}
1) Why are you passing parameters which you will never use?
void DisplayPay(int hours, const double HOURLYPAY); — this is ALL you need. Other variables should be local.
1
2
3
4
5
6
7
8
9
10
void DisplayPay(int hours, const double HOURLYPAY)
{
    int pay(0), netPay(0), overtime(0), overtimePay(0), dTime(0);
    if(40<=hours) {
        pay=hours*HOURLYPAY;
        netPay=pay;
    } else if (40 < hours && hours <= 45) { //There was an error in your code.
        pay = (HORLYPAY * 40);
        //...
}
Alright, all fixed. One error that has me completely baffled. I have never seen this error.

error LNK2019: unresolved external symbol "void __cdecl DisplayDeductions(double,double,double,double,double)" (?DisplayDeductions@@YAXNNNNN@Z) referenced in function _main
Check your DisplayDeductions function declaration, definition and call
Got it working Thanks for your help.
Topic archived. No new replies allowed.