### Output Problem

I'm working on a program to read the hours worked and rate of pay. It would then calculate the pay, taxes, deductions. I also have to account for overtime which is paid in time and a half. For an example you would input 47 hours and 15 \$/hour. It would then supposed to show this as the output.

40 hours regluar time: \$600.00
7 hours overtime: \$157.50
Total wages: \$757.50

Income Tax: \$128.00
Provincial Tax: \$53.03
CPP: \$29.54
EI: \$19.31

Net Income: \$526.84

Here is my code

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869`` ``````#include #include using namespace std; int main() { double hours=0; double rate =0; double pay=0; double overtime=0; double regPay=0; const double incomeTax=0.17; const double provTax=0.07; const double CPP=0.039; const double EI=0.0255; double TOTAL=0; double regPay=0; double OTPay=0; const double OTRate=1.5; double OTHours=0; //Get the number of hours worked. cout << "How many hours worked? "; cin >> hours; if (hours > 40) { overtime =hours-40; hours=40; } // Get the hourly pay rate. cout << "How much do you get paid per hour? "; cin >> rate; // Calculate the pay. pay = (hours * rate) + (overtime * (rate*1.5)); //Calculate the regular pay regPay=rate * 40; cout<<"Regular pay is: \$"<

With this code it would not output the regular pay and the overtime pay. Here is what the output is currently.
40 hours regluar time: \$600.00

Income Tax: \$128.00
Provincial Tax: \$53.03
CPP: \$29.54
EI: \$19.31

Net Income: \$526.84

Could someone explain in layman's terms why those two lines do not want to show.
Also, yes I know that some people will call me out on using system("pause"). If you have any questions feel free to ask.
Last edited on
If I have correctly understood your question then in line 31 you wrote

if (hours > 40)
{
overtime =hours-40;
hours=40;
}

So OTHours will be always equal to 0 if the initial value of hours was greater than 40.

OTHours=(hours-40); // == 0 becuase early hours was set to 40.
Also I think that the following code

//Calculate the regular pay
regPay=rate * 40;
cout<<"Regular pay is: \$"<<regPay<<endl;

also is logically incorrect because nothing prevents to enter the number of hours less than 40.

It would be good if you define named constant for the magic number 40.
Last edited on
But I want OTHours to equal whatever the overtime will be so it will output just what you get paid for overtime. But i think in those lines you said there are some errors in the if statements and im all out of ideas.
Topic archived. No new replies allowed.