8 Replies - 311 Views - Last Post: 13 May 2013 - 11:38 AM Rate Topic: -----

#1 Johnny567  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-May 13

Project Help

Posted 13 May 2013 - 08:52 AM

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

#include <iostream>
#include <iomanip>
#include <string>

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;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Project Help

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9494
  • View blog
  • Posts: 35,842
  • Joined: 12-June 08

Re: Project Help

Posted 13 May 2013 - 08:54 AM

Quote

. I am not getting any errors for the program, however it is not calculating the gross pay correctly.

Would you share what you are inputting, what is is the output, and what *should* be the output?
Was This Post Helpful? 0
  • +
  • -

#3 Johnny567  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-May 13

Re: Project Help

Posted 13 May 2013 - 08:58 AM

View Postmodi123_1, on 13 May 2013 - 08:54 AM, said:

Quote

. I am not getting any errors for the program, however it is not calculating the gross pay correctly.

Would you share what you are inputting, what is is the output, and what *should* be the output?


Sure, this is an example run of my program and the input/output of an "exempt" employee. Another problem you'll notice I'm facing is that the social security number comes out as 0 in the output for some reason.

----------------------------------------------------------------------------------------------------

Please enter the first name of the Employee: Student

Please enter the employee's social security number: 3333333

Please enter if the employee is exempt or non-exempt,
'e' for exempt or 'n' for nonexempt: e

Please enter the employee's year to date compensation: 30000

The Employee's Name is: Student
The Employee's Social Security Number is: 0
The Employee's status is: Exempt
Please enter the employee's weekly salary: 2000


The Medicare Tax is: $0.00
The Social Tax is: $0.00
The State Tax is: $50.00
The Federal Tax is: $100.00
The Employee's Gross Salary is: $1850.00
Press any key to continue . . .
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9494
  • View blog
  • Posts: 35,842
  • Joined: 12-June 08

Re: Project Help

Posted 13 May 2013 - 09:05 AM

Okay.. and what do you think the values should be?
Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg  Icon User is online

  • member icon


Reputation: 4232
  • View blog
  • Posts: 13,287
  • Joined: 25-December 09

Re: Project Help

Posted 13 May 2013 - 09:12 AM

First I recommend you use a string for the SSN, this "number" may be too big for your int data type, Plus most users would enter the SSN as 555-55-5555.

Next get rid of all those global variables, they are not needed and are confusing you. For example where do you ever enter a value for social? You called the SSN ssNum in the function, not social. Learn to properly pass the required values to and from your functions using parameters.

I suggest you study the function tutorials contained in my signature if you don't understand you to properly pass variables into your functions.

Jim
Was This Post Helpful? 0
  • +
  • -

#6 Johnny567  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-May 13

Re: Project Help

Posted 13 May 2013 - 09:14 AM

View Postmodi123_1, on 13 May 2013 - 09:05 AM, said:

Okay.. and what do you think the values should be?


Well, definately not 0.

But the social should be the gross pay * 6.2% since the year to date compensation and gross pay is less than the social wage base (113,700). The medicare should be the gross pay * 1.45% if its less than or equal to 200000, or if its greater than 200,000, the medicare tax should be the gross pay *1.45% + an extra 0.9%. As for the state tax, if the gross pay is less than or equal to 1,000, the state tax should be 5% * $1000, otherwise if the gross pay is more than 1,000 the state tax should be equal to 8% * the gross pay - 1000, + 5% * 1,000, as seen in the program. The federal calculations are listed under the federal function as well.

I think my main issue here is that the variables aren't passing to each function correctly, so their is a lot of missing data that the program is not properly reading.

View Postjimblumberg, on 13 May 2013 - 09:12 AM, said:

First I recommend you use a string for the SSN, this "number" may be too big for your int data type, Plus most users would enter the SSN as 555-55-5555.

Next get rid of all those global variables, they are not needed and are confusing you. For example where do you ever enter a value for social? You called the SSN ssNum in the function, not social. Learn to properly pass the required values to and from your functions using parameters.

I suggest you study the function tutorials contained in my signature if you don't understand you to properly pass variables into your functions.

Jim


The social was meant for the function that calculates the social security tax.
Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is online

  • member icon


Reputation: 4232
  • View blog
  • Posts: 13,287
  • Joined: 25-December 09

Re: Project Help

Posted 13 May 2013 - 09:20 AM

Study the function tutorials in my signature, look at the warnings your code generates.

Quote

main.cpp||In function ‘int main()’:|
main.cpp|40|warning: switch missing default case [-Wswitch-default]|
main.cpp||In function ‘double exemptCalc()’:|
main.cpp|99|warning: declaration of ‘grossPay’ shadows a global declaration [-Wshadow]|
main.cpp|7|warning: shadowed declaration is here [-Wshadow]|
main.cpp||In function ‘double socialCalc()’:|
main.cpp|145|warning: declaration of ‘social’ shadows a global declaration [-Wshadow]|
main.cpp|7|warning: shadowed declaration is here [-Wshadow]|
main.cpp||In function ‘double medicareCalc()’:|
main.cpp|169|warning: declaration of ‘medicare’ shadows a global declaration [-Wshadow]|
main.cpp|7|warning: shadowed declaration is here [-Wshadow]|
main.cpp||In function ‘double stateCalc()’:|
main.cpp|195|warning: declaration of ‘state’ shadows a global declaration [-Wshadow]|
main.cpp|7|warning: shadowed declaration is here [-Wshadow]|
main.cpp||In function ‘double federalCalc()’:|
main.cpp|210|warning: declaration of ‘federal’ shadows a global declaration [-Wshadow]|
main.cpp|7|warning: shadowed declaration is here [-Wshadow]|
||=== Build finished: 0 errors, 11 warnings ===|


Being caused by the global variables, and not properly passing the variables to the functions.

Jim
Was This Post Helpful? 0
  • +
  • -

#8 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1397
  • View blog
  • Posts: 4,872
  • Joined: 19-February 09

Re: Project Help

Posted 13 May 2013 - 09:22 AM

Is the regular rate not the same as the hourly rate? Also if you multiply by 0.5 you are halving the rate.

134	    regular_rate = totalRegPay/hours_worked;
135	    overtime_rate = regular_rate * 0.5;




You could simplify the main function by using the switch to just calculate the gross pay in each case.
Was This Post Helpful? 0
  • +
  • -

#9 Johnny567  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-May 13

Re: Project Help

Posted 13 May 2013 - 11:38 AM

View Post#define, on 13 May 2013 - 09:22 AM, said:

Is the regular rate not the same as the hourly rate? Also if you multiply by 0.5 you are halving the rate.

134	    regular_rate = totalRegPay/hours_worked;
135	    overtime_rate = regular_rate * 0.5;




You could simplify the main function by using the switch to just calculate the gross pay in each case.


Thank you for the helpful advice, I will try to implement this and then report back with my findings.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1