Problem with simple calculation
Nov 23, 2017 at 6:32pm UTC
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.
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
#include <iostream>
#include <iomanip>
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 Nov 24, 2017 at 7:34pm UTC
Dec 1, 2017 at 8:00pm UTC
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
Topic archived. No new replies allowed.