In: Computer Science
C++
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:
Prompt the user to enter the following information:
Your program must consist of at least the following functions:
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.)
Code
#include<iostream>
using namespace std;
// function to calculate tax
void taxAmount(char status, int child, float salary)
{
float tax, excemption, net_tax, taxable_income; // variable declaration
if(status == 'u') // if person is unmarried
excemption = 4000 + (0.06 * salary) + 1500; // calculate excemption
else // if person is married
excemption = 7000 + (0.06 * salary) + (1500 * (2+child)); // calculate excemption
taxable_income = salary - excemption; // calculate taxable income after subtracting excemption
if(taxable_income <= 15000) // if taxable_income is less than 15000
tax = 0.15 * taxable_income;
else if(taxable_income > 15000 && taxable_income <= 40000) // taxable_income between 15000 and 40000
tax = 2250 + (taxable_income - 15000) * 0.25;
else // taxable income greater than 40000
tax = 8460 + (taxable_income - 40000) * 0.35;
cout<<"Federal Tax: "<<tax<<endl; // print federal tax
}
// function to take the input
void getData()
{
char status; // variable declaration
int child=0;
float salary;
cout<<"Enter the marrital status: (m or u) ";// marrital status
cin>>status;
if(status=='m') // if person is married
{
cout<<"Enter the number of child below 14: ";
cin>>child; // take no. of child below 14 as input
}
cout<<"Enter the gross salary: "; // gross salary
cin>>salary;
taxAmount(status, child, salary); // function call to calculate tax amount
}
// main function
int main()
{
getData(); // function call to take input
return 0;
}
Screenshot
Part 1
Part 2
Output 1: If person is married
Output 2:if person is unmarried
Comments has been given in the code. Also, screenshot of the code as well the output has been given for the reference.