### Help with Salary Program

Hello, so I've been having some difficulties with a C++ programming assignment. We have to create a program that calculates the Gross Pay based on factors such as social, medicare, federal taxes, and exempt/nonexempt status. I have uploaded the assignment instructions to an image hosting site below. I am not getting any errors for the program, however it is not calculating the gross pay correctly.

http://i.imgur.com/CMLnUk2.png
http://i.imgur.com/l2nyDNc.png
http://i.imgur.com/1lQUQNo.png

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225`` ``````#include #include #include using namespace std; double grossPay, ytdcomp, medicare, social, state, federal; double exemptCalc(); double nonexemptCalc(); double socialCalc(); double medicareCalc(); double federalCalc(); double stateCalc(); int main() { double ExPayGross,nonExPayGross; int ssNum; string employee; char status; cout << "Please enter the first name of the Employee: "; cin >> employee; cout << "\nPlease enter the employee's social security number: "; cin >> ssNum; cout << "\nPlease enter if the employee is exempt or non-exempt,\n'e' for exempt or 'n' for nonexempt: "; cin >> status; cout << "\nPlease enter the employee's year to date compensation: "; cin >> ytdcomp; switch (status) { case 'E': case 'e': cout << "\nThe Employee's Name is: " << employee; cout << "\nThe Employee's Social Security Number is: " << social; cout << "\nThe Employee's status is: Exempt "; cout << fixed << showpoint; cout << setprecision(2); ExPayGross = exemptCalc(); medicare = medicareCalc(); social = socialCalc(); state = stateCalc(); federal = federalCalc(); cout << "\nThe Medicare Tax is: \$" << medicare; cout << "\nThe Social Tax is: \$" << social; cout << "\nThe State Tax is: \$" << state; cout << "\nThe Federal Tax is: \$" << federal; cout << "\nThe Employee's Gross Salary is: \$" << (ExPayGross) - (medicare + social + state + federal); cout << endl; break; case 'N': case 'n': cout << "\nThe Employee's Name is: " << employee; cout << "\nThe Employee's Social Security Number is: " << social; cout << "\nThe Employee's status is: Non-Exempt "; nonExPayGross = nonexemptCalc(); medicare = medicareCalc(); social = socialCalc(); state = stateCalc(); federal = federalCalc(); cout << "\nThe Medicare Tax is: \$" << medicare; cout << "\nThe Social Tax is: \$" << social; cout << "\nThe State Tax is: \$" << state; cout << "\nThe Federal Tax is: \$" << federal; cout << "\nThe Employee's Gross Salary is: \$" << (nonExPayGross) - (medicare + social + state + federal); cout << endl; break; } return 0; } double exemptCalc() { double grossPay, wklyComp; cout << "\nPlease enter the employee's weekly salary: "; cin >> wklyComp; cout << endl; grossPay = wklyComp; return grossPay; } double nonexemptCalc() { double hourly_pay, hours_worked, hourly_rate, totalRegPay, overtime_rate, overtime_pay, totalPay, regular_rate; cout << "\nPlease enter the employee's hourly rate of pay: "; cin >> hourly_rate; cout << "\nPlease enter the employee's hours worked: "; cin >> hours_worked; hourly_pay = hours_worked * hourly_rate; totalRegPay = hourly_pay + ytdcomp; if (hours_worked <= 40) { totalPay = totalRegPay; } else if (hours_worked > 40) { regular_rate = totalRegPay/hours_worked; overtime_rate = regular_rate * 0.5; overtime_pay = (hours_worked - 40) * overtime_rate; totalPay = totalRegPay + overtime_pay; } return totalPay; } double socialCalc() { double social, ss_exempt_amt, ss_taxable_amt; const double ssa_wage_base = 113700.00; if (ytdcomp > ssa_wage_base) social = 0; else if ((ytdcomp + grossPay) <= ssa_wage_base) social = grossPay * .062; else if ((ytdcomp + grossPay) > ssa_wage_base) { ss_exempt_amt = ytdcomp + grossPay - ssa_wage_base; ss_taxable_amt = grossPay - ss_exempt_amt; social = ss_taxable_amt * .062; } return social; } double medicareCalc() { double medicare, extraMedTaxAmount, regMedTaxAmount; const double med_threshold = 200000.00; const double med_extra = 0.009; if (ytdcomp > med_threshold) medicare = grossPay * (.0145 + med_extra); else if ((ytdcomp + grossPay) <= med_threshold) medicare = grossPay * .0145; else if ((ytdcomp + grossPay) > med_threshold) { extraMedTaxAmount = ytdcomp + grossPay - med_threshold; regMedTaxAmount = grossPay - extraMedTaxAmount; medicare = regMedTaxAmount * .0145; medicare = medicare + (extraMedTaxAmount * (.0145 + med_extra)); } return medicare; } double stateCalc() { double state; if (grossPay <= 1000) state = (.05 * 1000); else if (grossPay > 1000) state = (.08) * (grossPay - 1000) + (.05 * 1000); return state; } double federalCalc() { double federal; if (grossPay <= 1000) federal = (.10 * 1000); else if (grossPay <= 2500) federal = (.15) * (grossPay - 1000) + (.10 * 1000); else if (grossPay > 2500) federal = (.25) * (grossPay - 2500) + (.15) * (grossPay - 1500) + (.10 * 1000); return federal; }``````
Last edited on
closed account (N85iE3v7)
Hey

If it is compiling you can debug it!

First try to calculate the values manually, so you will know if they formulas are all ok. It might be possible that you will find your problem here.

If not,

You know what it would be expected after execution of every function in your program, so put breakpoints over there and execute them step by step.

Another tip, write a simple headline for every function and describe its functionality, for example, giving numerical examples for every function. This helps to make the code clear and easy to look at. It might be a good idea not to have IO inside the functions that make the calculations. Not worries at this anyway.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian Kernighan
Topic archived. No new replies allowed.