### Problem with simple calculation

I am a student in college and i have this first assignment to calculate netpay. the calculation of the gross pay, prsi, paye, and usc come out as correct but when i take it away from the net pay the net pay is wrong. The net pay is supposed to equal 554.08. This assignment is due tomorrow so if u have the slightest idea i would appreciate the help.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120`` ``````#include #include using namespace std; class Payroll { public: float get_gross_pay(float hours, float rate); float get_usc(float gross_pay); float get_paye(float gross_pay); float get_eeprsi(float gross_pay); float get_net_pay(); void display_payslip(); private: float dm_hours; float dm_rate; float dm_gross; float dm_prsi; float dm_paye; float dm_usc; float dm_tax_credit = 31.73; float dm_netpay; }; float Payroll::get_gross_pay(float hours, float rate) { dm_hours = hours; dm_rate = rate; dm_gross = dm_hours * dm_rate; return dm_gross; } float Payroll::get_usc(float gross_pay) { if (dm_gross <=231) { dm_usc = (dm_gross * 0.01); } if (dm_gross >231 && dm_gross <=359) { dm_usc = ((dm_gross - 231) * 0.03) + 2.31; } if (dm_gross >359 && dm_gross <=1347) { dm_usc = ((dm_gross - 359) * 0.055) + 6.15; } if (dm_gross >1347) { dm_usc = ((dm_gross - 1347)* 0.08) + 60.49; } return dm_usc; } float Payroll::get_paye(float gross_pay) { if (dm_gross <= 650) { dm_paye =(dm_gross * .2); } if (dm_gross > 650) { dm_paye = ((dm_gross - 650) * .4 + (650 * .2)); } return dm_paye; } float Payroll::get_eeprsi(float gross_pay) { dm_gross = gross_pay; dm_prsi = ((dm_gross) * 0.04); return dm_prsi; } float Payroll::get_net_pay() { dm_netpay = dm_gross - (dm_paye + dm_prsi + dm_usc ); return dm_netpay; } void Payroll::display_payslip() { cout << setw(20) <<" ______________________________________________" << endl; cout << setw(20) <<"| |" << endl; cout << setw(20) <<"| Weekly Payslip |" << endl; cout << setw(20) <<"| |" << endl; cout << setw(10) << setprecision(2) << fixed << "| Gross pay " << setw(25) << dm_gross << setw(6) << "|" << endl; cout << setw(20) <<"| |" << endl; cout << setw(10) <<"| PAYE - Tax Credit " << setw(10) << dm_paye - dm_tax_credit << setw(13) << "|" << endl; cout << setw(20) <<"| |" << endl; cout << setw(10) <<"| USC " << setw(23) << dm_usc << setw(14) << "|" << endl; cout << setw(20) <<"| |" << endl; cout << setw(10) <<"| EE PRSI " << setw(19) << dm_prsi << setw(14) << "|" << endl; cout << setw(20) <<"| |" << endl; cout << setw(20) <<"| |" << endl; cout << setw(10) <<"| Net pay " << setw(27) << dm_netpay << setw(6) << "|" << endl; cout << setw(20) <<"|______________________________________________|" << endl; } float paye; float gross_pay; float prsi; int hours; float rate; float usc; float net_pay; int main() { class Payroll employee1; cout << "ENTER THE HOURS WORKED" << endl; cin >> hours; cout << "ENTER THE HOURLY RATE" << endl; cin >> rate; gross_pay = employee1.get_gross_pay(hours, rate); prsi = employee1.get_eeprsi(gross_pay); paye = employee1.get_paye(gross_pay); usc = employee1.get_usc(gross_pay); net_pay = employee1.get_net_pay(); employee1.display_payslip(); return 0; }; ``````
Last edited on
Hello Ayoub Hashemi,

Welcome to the forum.

Sorry for the delay, but when you wait until the last minute this is what happens.

If you are still watching this.

What prints to the screen looks like what should be used to figure net pay, but the variables you use have a different result.

Given the input of 40 hours @ \$15/hour this line:
`dm_netpay = dm_gross - (dm_paye + dm_prsi + dm_usc );`
will produce:
 `436.60 = 600 - (120.0 + 24.0 + 19.41)`

The numbers on the screen ay that net pay is 468.32.

The screen shows:
 ``` ______________________________________________ | | | Weekly Payslip | | | | Gross pay 600.00 | | | | PAYE - Tax Credit 88.27 | | | | USC 19.41 | | | | EE PRSI 24.00 | | | | | | Net pay 436.60 | |______________________________________________| ```

The three middle numbers subtracted from 600 do not match the net pay shown.

I have not tracked everything down yet, but part of the problem comes the code that prints the above output and part comes from the "get_net_pay" function. I would say that both need some adjusting.

Hope that helps,

Andy