Function problem

I am unsure why my { bracket in my DisplayDeductions function says that it expected a declaration. Also linking my DisplayPay to my DisplayDeductions to transfer the values is not working for me. Any help would be great.

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
#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);

void DisplayNetpay(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);

		//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);
{
	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;
}
You have a ";" from coping the function prototype right here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void DisplayDeductions(double Taxes, double CPP, double EI, double UD, double Money);
                                                                                    ^
{
	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;
}


And as for the linking, declare the variables in main and then in the function prototype and the function definition, insert a & before the variable name. So like
void DisplayNetpay(double NetPay);
would become
void DisplayNetpay(double &NetPay);
and you would declare NetPay in int main.
Last edited on
Would I declare my functions before my return and after my while in my int main?
I'm talking about the literal variables. So like here:

1
2
3
4
5
6
7
int main() 
{ 
	int hours=0;
	char repeat = 'y';
        double NetPay;
	
	//user instructions 


If you wanted to use NetPay in another function, and have your DisplayDeductions function save a new value in the actual NetPay(my new one in int main).

Oh, and you are calling variables that have not been made in int main as well.
So this in int main:
void DisplayPay (int hours, double RegPay, double OverTPay, double Pay, const double HOURLYPAY, double OT, double DTime);
Has no values to "carry over" into that function because they haven't been initialized.
Topic archived. No new replies allowed.