In: Computer Science
Write a program that can be used to calculate the federal tax. The tax is calculated as follows: For single people, the standard exemption is $4,000; for married people, the standard exemption is $7,000. A person can also put up to 6% of his or her gross income in a pension plan. The tax rates are as follows: If the taxable income is:
To calculate the taxable income, subtract the sum of the standard exemption, the amount contributed to a pension plan, and the personal exemption, which is $1,500 per person. (Note that if a married couple has two children under the age of 14, then the personal exemption is $1,500 ∗ 4 = $6,000.)
Since your program handles currency, make sure to use a data type that can store decimals with a decimal precision of 2.
Program:
#include <iostream>
using namespace std;
void getData(char *m,int *s, float *g, float *p, int *c, float
*t)
{
cout<<"Are you married?(Y/N): ";
cin>>*m;
if(*m=='Y')
{
*s=7000;
cout<<"Enter number of children you have below 14 years of
age: ";
cin>>*c;
cout<<"Enter combined salary of both the spouses, if both
have income. Else enter only your income: ";
cin>>*g;
cout<<"Enter percentage(must be less than 6%) of gross income
contributed to a pension fund: ";
cin>>*p;
if((*p)<0||(*p)>6)
{
while((*p)>=0&&(*p)<=6)
{
cout<<"Percentage must be between 0 and 6, both inclusive.:
";
cin>>*p;
}
}
*t=*g-(*s+((*p)*(*g))/100+(2+(*c))*1500);
}
else
{
*s=4000;
cout<<"Enter gross salary: ";
cin>>*g;
cout<<"Enter percentage(must be less than 6%) of gross income
contributed to a pension fund: ";
cin>>*p;
if((*p)<0||(*p)>6)
{
while((*p)>=0&&(*p)<=6)
{
cout<<"Percentage must be between 0 and 6, both inclusive.:
";
cin>>*p;
}
}
*t=*g-(*s+(((*p)*(*g))/100)+1500);
}
}
float taxAmount(float t)
{
if(t<=15000)
return (0.15*t);
else if(t>15000&&t<=40000)
return (2250+(0.25*(t-15000)));
else
return (8460+(0.35*(t-40000)));
}
int main()
{
char maritalStatus;
float grossSalary,pensionPlanContribution,taxableIncome,tax;
int childrens=0,standardExemption;;
getData(&maritalStatus,&standardExemption,&grossSalary,&pensionPlanContribution,&childrens,&taxableIncome);
tax=taxAmount(taxableIncome);
cout<<"\nTax owed = "<<tax;
return 0;
}
Screenshot of the Code:
Output 1:
Output 2: