# Problem with Tax Project

Page 1 of 1

## 7 Replies - 1538 Views - Last Post: 13 May 2013 - 07:53 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=320954&amp;s=6848ffffeba5fe74dd37ffd6d727a277&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 cerlmc

• New D.I.C Head

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

# Problem with Tax Project

Posted 13 May 2013 - 08:52 AM

c++ federal income tax must be withheld from the employee's gross pay. for this project, federal income tax is 10% of gross pay for the first \$1000, 15% on the next \$15000 and 25% on amounts above \$2500, So it should calculate like gross pay is \$4000.00 then 10% of the first 1000 = 100, then 15% of the next \$1500 = \$225 and then 25% on the any amount left over \$2,500 in this case would be \$1500 * 25% = 375 So total's for all three brackets are \$700.

I'm trying to use if statemetns but i'm having trouble storing each amount in a particular variable and not having them over lap - and then add them up at the end to get my total?

Trying to do something like this
```
if (fedTotalPay>0 && fedTotalPay <=1000)
fedtax =.10 * fedTotalPay;

if (fedTotalPay >1000)
(fedtax1 = (fedTotalPay -1000)) *.10;

if (fedTotalPay >1000 && fedTotalPay <2500)
(fedtax2 = (fedTotalPay -1500)) *.15;
if (fedTotalPay >2500)
(fedtax3 = (fedTotalPay -2500)) *.25;

totalfedtax = fedtax+fedtax1+fedtax2+fedtax3;

```

Thank You

Is This A Good Question/Topic? 0

## Replies To: Problem with Tax Project

### #2 jimblumberg

Reputation: 4736
• Posts: 14,768
• Joined: 25-December 09

## Re: Problem with Tax Project

Posted 13 May 2013 - 09:00 AM

Look closely at the following snippet:
``` if (fedTotalPay >1000)
...
if (fedTotalPay >1000 && fedTotalPay <2500)
```

You may want to consider if/else if() statements.
```if(Pay <= 1000)
...
else if(Pay < 2000)
...
else
... Everything else.
```

Take care of the less than zero separately.

Jim

### #3 cerlmc

• New D.I.C Head

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

## Re: Problem with Tax Project

Posted 13 May 2013 - 09:41 AM

I appreciate the help, but still can't get it right- I hope I'm being clear with my question, but Im getting hung up on the fact that I have to store a certain percentage in each variable and then be able to add them all up seperately to deduct the total?

### #4 brettlee54

• New D.I.C Head

Reputation: 0
• Posts: 10
• Joined: 02-October 08

## Re: Problem with Tax Project

Posted 13 May 2013 - 10:01 AM

cerlmc, on 13 May 2013 - 09:41 AM, said:

I appreciate the help, but still can't get it right- I hope I'm being clear with my question, but Im getting hung up on the fact that I have to store a certain percentage in each variable and then be able to add them all up seperately to deduct the total?

Consider the if-else statement as mentioned above.
And also look into the following expressions, it might be a syntax error to do as you have.

```fedtax2 = (fedTotalPay -1500) *.15;

```

Lose the brackets.

### #5 Zereo

Reputation: 44
• Posts: 108
• Joined: 08-November 12

## Re: Problem with Tax Project

Posted 13 May 2013 - 10:50 AM

I'm not sure I am understanding what you are having trouble with exactly but I'm going to take a guess. Are you having trouble keeping track of all the different tax brackets taxes so you can add them up at the end to get the total?

Create a variable to store each of the tax brackets tax. That way at the end of the program you can just add them 3 variables together.

```// This will hold the total tax amount for
// the 10% of \$1000;
double lowTax;

// This will hold the total tax amount for
// the 15% of \$1500
double midTax;

// This will hold the tax for everything else leftover
// at 25%.
double highTax;

//Then at the end of the program once we got all the values stored
// we can just do something like this

double totalTax = lowTax + midTax + highTax;
```

It might also be a good idea to make variables that hold each brackets rates in them like
```const double lowRate = .10;
```

That way they can easily change if needed in the future.

### #6 cerlmc

• New D.I.C Head

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

## Re: Problem with Tax Project

Posted 13 May 2013 - 12:07 PM

yes I tried to do that with the

totalfedtax = fedtax+fedtax1+fedtax2+fedtax3;

but what seems to happen is I get over lap - like if the first bracket is supposed to store 10 % then the next 15%, and the last 25\$ but only on a certain amount it seems to take the entire gross pay and do the calculation and not less of the first 1000, second 1500.

### #7 Zereo

Reputation: 44
• Posts: 108
• Joined: 08-November 12

## Re: Problem with Tax Project

Posted 13 May 2013 - 01:08 PM

Could you post your complete code so we can see what you have so far? It will help give us a better idea on where we can help.

### #8 cerlmc

• New D.I.C Head

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

## Re: Problem with Tax Project

Posted 13 May 2013 - 07:53 PM

sure

```#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>

using namespace std;

//declare variables
string employeeName="";
string ssn="";
string status="";

//Declare initialized variables
char ch;
int hoursWorked=0;
double TotalPay=0;
double SSNTax=6.2;
double taxAmount=0;
double ssnTaxAmount=0;
double netPay=0;
double YTD=0;
double salary=0;
double bonus=0;
double hourlyPayRate=0;
double compensation=0;

//Variables for Medicare Tax
double extraMedtaxamount;
double regMedtaxamount;
const double medRate =.0145;
const double extraMedrate = .0235;
const double medThreshold = 2000000.00;
double medicareTax=0;
//Variables for New York State Income Tax
double nysTax1;
double nysTax2;
double nysTotaltax;

//Variables for Federal Income Tax
double fedtax1;
double fedtax2;
double fedtax3;
double totaloffedtaxes;

//Declare Function Prototypes
double calculateTotalPay(string status);
double calculateFedTax();
double calculateSsnTax();
void displayOutput();
//main start
int main()
{
do{
//ask user for employee name
cout<<"Enter the Employee's name: ";
getline(cin,employeeName);
//ask user for ssn
cout<<"Enter the Employee's SSN: ";
cin>>ssn;
//ask user for status of employee = Exempt or Non-Exempt
do{
cout<<"Enter employee status (N/E): ";
cin>>status;
status=toupper(status[0]);
}while(status!="N" && status!="E");
//ask user for year to date compensation
cout<<"Enter Employee year to date compensation: ";
cin>>YTD;
/*
If the status is E, the program will ask for the employee’s salary and bonus
if any and any other compensation if any.*/
if(status=="E")
{
cout<<"Enter salary: ";
cin>>salary;
cout<<"Is there any bonus (Y/N): ";
cin>>ch;
ch=toupper(ch);
if(ch=='Y')
{
cout<<"Enter bonus: ";
cin>>bonus;
}
cout<<"Is there any additional compensation (Y/N): ";
cin>>ch;
ch=toupper(ch);
if(ch=='Y')
{
cout<<"Enter additional compensation: ";
cin>>compensation;
}
}
/*If the status is N, the program will ask the user to enter the employee’s hourly rate of pay,
hours worked, bonus if any, and other compensation if any.*/
else if (status=="N")
{
cout<<"Enter hourly pay rate: ";
cin>>hourlyPayRate;
cout<<"Enter hours worked: ";
cin>>hoursWorked;
cout<<"Is there any bonus's (Y/N): ";
cin>>ch;
ch=toupper(ch);
if(ch=='Y')
{
cout<<"Enter bonus amount: ";
cin>>bonus;
}
cout<<"Is there any additional compensation (Y/N): ";
cin>>ch;
ch=toupper(ch);
if(ch=='Y')
{
cout<<"Enter additional  compensation: ";
cin>>compensation;
}
}
//call function to calculate total pay
TotalPay=calculateTotalPay(status);

//call functions to calculate tax deductions
taxAmount= calculateFedTax();
ssnTaxAmount=calculateSsnTax();

//calculate netPay
netPay = TotalPay-calculateSsnTax()-calculateFedTax();

/*Calculate medicare tax
Medicare tax is 1.45% for an employee on annual compensation up to and including
\$200,000 (Year-to-Date Compensation – everything paid to the employee so far). For
amounts in excess of \$200,000, the employee Medicare tax rate is 2.35% (an additional
0.9%) */

{

if(YTD + bonus + compensation <= 200000)
medicareTax =  medRate * TotalPay;
if ((YTD + bonus + compensation) > 200000)
medicareTax = extraMedrate * TotalPay;

}

//Calculate New ork State Income Tax
/*
Withhold New York State income tax as follows for each employee:
5% of gross pay up to and including, \$1,000
Tax on amounts up to \$1,000 plus 8% on amounts above \$1,000 */
{

if (TotalPay <= 1000)
nysTax1 = .05 * TotalPay;

if (TotalPay > 1000)
nysTax2 = ((TotalPay-1000) * .08) +100;

nysTotaltax = nysTax1 + nysTax2;

}

netPay = netPay - medicareTax;
netPay= netPay - nysTotaltax;

displayOutput();

//ask user to continue
cout<<"Do you want to continue and Process another Employee? (Y/N): ";
cin>>ch;
ch=toupper(ch);
cin.ignore();
}while(ch=='Y');

system("pause");
return 0;
}
//Display Ouput on Screen
void displayOutput()
{
cout << fixed << showpoint << setprecision(2);
cout<<endl<<"====================================================="<<endl;
cout<<setw(30)<<"Employee Name: "<<employeeName<<endl;
cout<<setw(30)<<"Social Security Number: "<<ssn<<endl;
cout<<setw(30)<<"Status: "<<status<<endl;
if(status=="E"){
cout<<setw(30)<<"Salary rate: "<<salary<<endl;
}else if(status=="N"){
cout<<setw(30)<<"Hourly rate: "<<hourlyPayRate<<endl;
}
cout<<setw(30)<<"Gross Pay: "<<TotalPay<<endl;
cout<<setw(30)<<"Federal Income Tax Withheld: "<<taxAmount<<endl;
cout<<setw(30)<<"Total of Federal Income Tax Withheld: "<<totaloffedtaxes<<endl;
cout<<setw(30)<<"Social Security Tax Withheld: "<<ssnTaxAmount<<endl;
cout<<setw(30)<<"Medicare Tax Withheld: "<<medicareTax<<endl;
cout<<setw(30)<<"New York State Income Tax: "<<nysTotaltax<<endl;
cout<<setw(30)<<"Net Pay to the Employee: "<<netPay<<endl;
cout<<"====================================================="<<endl;

//write output to file
ofstream fout;
fout.open("Employee Report.txt",ios::app);
fout<<endl<<"====================================================="<<endl;
fout << fixed << showpoint << setprecision(2);
fout<<setw(30)<<"Employee Name: "<<employeeName<<endl;
fout<<setw(30)<<"Social Security Number: "<<ssn<<endl;
fout<<setw(30)<<"Status: "<<status<<endl;
if(status=="E"){
fout<<setw(30)<<"Salary rate: "<<salary<<endl;
}else if(status=="N"){
fout<<setw(30)<<"Hourly rate: "<<hourlyPayRate<<endl;
}
fout<<setw(30)<<"Gross Pay: "<<TotalPay<<endl;
fout<<setw(30)<<"Federal Income Tax Withheld: "<<taxAmount<<endl;
fout<<setw(30)<<"Social Security Tax Withheld: "<<ssnTaxAmount<<endl;
fout<<setw(30)<<"Medicare Tax Withheld: "<<medicareTax<<endl;
fout<<setw(30)<<"New York State Income Tax: "<<nysTotaltax<<endl;
fout<<setw(30)<<"Net Pay to the Employee: "<<netPay<<endl;
fout<<"====================================================="<<endl;
fout.close();
}

/*
Social Security Tax:
The tax is 6.2% on the first \$113,700 of an employee's yeartodate plus current compensation.
If year to date is already over \$113,700, the social security tax rate is 0% and there is no social
security tax. If year to date plus gross pay is less than \$113,700, then social security tax on
gross pay is 6.2% of the amount. If year to date is less than \$113,700 but year to date plus
gross pay is greater than \$113,700, then there is social security tax on the amount brings year to
date to \$113,700
*/
double calculateSsnTax()
{
double tax;
if(YTD>113700){
return 0;//Means No tax
}
if((TotalPay+YTD)<113700)
{
tax=(TotalPay*SSNTax)/100;
return tax;
}
if(YTD<113700 && (TotalPay+YTD)>113700)
{
tax=((113700-YTD)*SSNTax)/100;
return tax;
}
return 0;
}

/*Calculate Federal Income Tax
Federal income tax must be withheld from the employee’s gross pay. For this project,
federal income tax is:
10% of gross pay for the first \$1000
15% of gross pay on the next \$1500
25% on amounts above \$2500*/

double calculateFedTax()
{

if(TotalPay<=1000)
return fedtax1= (TotalPay*0.10);
if(TotalPay>1000 && TotalPay <=2500)
return fedtax2= ((TotalPay-1000)*0.15 +100);
if (TotalPay > 2500)
return fedtax3= ((TotalPay-2500)*0.25) +100+225;

totaloffedtaxes = fedtax1+fedtax2+fedtax3;

return 0;
}

double calculateTotalPay(string status)
{
double TotalPay=0;
/*For employees with status E, the gross pay is the employee’s
salary + bonus if any + other compensation if any.*/
if(status=="E")
{
TotalPay=salary+bonus+compensation;
}
/*
For employees with status N, you must also pay the employee overtime
for hours worked over 40 in a workweek. Here is how to calculate this:
HourlyPay = HoursWorked * HourlyRate
TotalRegularPay = HourlyPay + Bonus + OtherCompensation
If HoursWorked< 40, then
TotalPay = TotalRegularPay
If HoursWorked> 40
RegularRate = TotalRegularPay / HoursWorked
OvertimeRate = RegularRate * 0.5
OvertimePay = (HoursWorked – 40) * OvertimeRate
TotalPay = TotalRegularPay + OvertimePay

*/
else if(status=="N")
{
int overtime=0;
double HourlyPay = hoursWorked * hourlyPayRate;
double TotalRegularPay = HourlyPay + bonus + compensation;
if (hoursWorked<= 40)
TotalPay = TotalRegularPay;
else if (hoursWorked> 40)
{
double RegularRate = TotalRegularPay / hoursWorked;
double OvertimeRate = RegularRate * 0.5;
double OvertimePay = (hoursWorked - 40) * OvertimeRate;
TotalPay = TotalRegularPay + OvertimePay;
}
}
}

```

Project is as followed: I'm having trouble with the federal portion and new york state income
Write the simplified weekly payroll program below that will compute the gross pay and
deduct federal income tax, social security and Medicare taxes from an employee’s
compensation.

The program should require initial inputs of the employee’s name, social security
number, status (E for exempt, N for nonexempt) and the year-to-date compensation [to
determine SS tax on the week’s gross pay and the Medicare tax on the week’s gross
pay].
If the status is E, the program will ask for (1) the employee’s weekly salary.
If the status is N, the program will ask the user to enter (1) the employee’s hourly rate of
pay, (2) hours worked, and (3) bonus if any or other compensation if any [just enter in
ONE NUMBER].
Gross Pay [Gross Amount of What The Employee is Being Paid This Week]
The program must compute the employee’s gross pay.
For employees with status E, the gross pay is the employee’s salary. NOTE: Enter the
salary as a weekly amount.
For employees with status N, you must also pay the employee overtime for hours
worked over 40 in a workweek. Here is how to calculate this:
HourlyPay = HoursWorked * HourlyRate
TotalRegularPay = HourlyPay + Bonus + OtherCompensation
If HoursWorked <= 40, then
TotalPay = TotalRegularPay
If HoursWorked > 40
RegularRate = TotalRegularPay / HoursWorked
OvertimeRate = RegularRate * 0.5
OvertimePay = (HoursWorked – 40) * OvertimeRate
TotalPay = TotalRegularPay + OvertimePay

Federal Income Tax
Federal income tax must be withheld from the employee’s gross pay. For this project,
federal income tax is:
 10% of gross pay for the first \$1000;
 15% of gross pay on the next \$1500;
 25% on amounts above \$2500. BCS120PM1 Final Project: Page 2 of 3
Example: Employee’s gross pay is \$4,000. Federal income tax is \$600, as follows:
Gross Pay: \$4,000
Less (1st \$1,000) \$1,000 x 10% = \$100
Subtotal \$3,000
Less (next \$1,500) \$1,500 x 15% = \$225
Subtotal (amounts over \$2,500) \$1,500 x 25% = \$375
TOTAL \$700
New York State Income Tax:
Withhold New York State income tax as follows for each employee:
 5% of gross pay up to and including, \$1,000
 Tax on amounts up to \$1,000 plus 8% on amounts above \$1,000
Example: Employee’s gross pay is \$2,400 for the week:
NY State:
Gross Pay: \$2,400
Less (tax on 1st \$2,000) \$1,000 x 5% = \$50
Subtotal (amounts over
\$1,000) \$1,400 x 8% = \$112
TOTAL \$162

Social Security Tax:
The tax is 6.2% on the first \$113,700 of an employee's year-to-date plus current
compensation. If year-to-date is already over \$113,700, the social security tax rate is
0% and there is no social security tax. If year-to-date plus gross pay is less than
\$113,700, then social security tax on gross pay is 6.2% of the amount. If year-to-date is
less than \$113,700 but year-to-date plus gross pay is greater than \$113,700, then there
is social security tax on the amount brings year-to-date to \$113,700 (HINT: You have
already done this in your last regular bonus assignment).
Medicare Tax:
Medicare tax is 1.45% for an employee on annual compensation up to and including
\$200,000 (Year-to-Date Compensation – everything paid to the employee so far). For
amounts in excess of \$200,000, the employee Medicare tax rate is 2.35% (an additional
0.9%) (HINT: You have already done this in your last regular bonus assignment).
Other Requirements:
The program must run for as many employees as the user cares to enter data for
(repetition). BCS120PM1 Final Project: Page 3 of 3
The program MUST output to the screen all of the data input for the employee, plus ALL
calculations including gross pay, the deductions, and net pay. Output screen is the
same as the outputs listed in “Extra Credit” below.
USE USER-DEFINED functions for each of the modules apparent in the program (e.g.,
gross wages [gross pay] of exempt employee, gross wages [gross pay] wages of
nonexempt employee, Federal income tax determination, social security tax
determination, Medicare tax determination, others you can think of for this project).
Finally, integrate other programming concepts learned during this course, as
appropriate (e.g., precision to 2 places, etc.).
Extra Credit:
In addition to the above, create an output file that has a record for each employee
processed that includes: [these items will also be your output for the above]
Employee Name
Social Security Number
Status (E or N)
Hourly rate (if status N) OR Salary Rate (if status E)
Gross Pay
Federal Income Tax Withheld
Social Security Tax Withheld
Medicare Tax Withheld
Net Pay to the Employee

This post has been edited by GunnerInc: 13 May 2013 - 07:57 PM
Reason for edit:: Fixed broken code tags