Question: Write a program that can be used to calculate the federal tax. This is my code, my output is correct but i get this error:

Write a program that can be used to calculate the federal tax.
This is my code, my output is correct but i get this error:
Status: FAILED! Check: 4 Test: Successful Output II Reason: Unable to find '['74785.33']' in the program's output. Enter M for married or S for single: Enter gross salary: Enter pension fund percentage (up to 6%): Marital Status: Single Number of People: 1 Income earned: $250001.00 Pension Plan Contribution: $15000.06 Taxable Income: $231000.94 The federal tax payable is: $75310.33. Error : AssertionError - Unable to find a number close enough to 74785.33(+/-0.00) in the program's output.
here is my code:
#include
#include
#include
using namespace std;
void getData(char &mStatus, int &numOfPpl, double &grossSalary, double &pensionFund){
cout << "Enter M for married or S for single: ";
cin >> mStatus;
mStatus = toupper(mStatus);
if (mStatus =='M'){
int children;
cout << "Enter number of children under 14: ";
cin >> children;
numOfPpl =2+ children;
} else {
numOfPpl =1;
}
cout << "Enter gross salary: ";
cin >> grossSalary;
cout << "Enter pension fund percentage (up to 6%): ";
cin >> pensionFund;
if (pensionFund >0 && pensionFund <=6){
pensionFund =(pensionFund /100.0)* grossSalary;
} else {
cout << "Invalid percentage. Please enter a value up to 6%.
";
}
}
double taxAmount(char mStatus, int numOfPpl, double grossSalary, double pensionFund){
double standardExemption =(mStatus =='M')?7000 : 4000;
double personalExemption =(mStatus =='M')?1500.0* numOfPpl : 0;
double taxableIncome = grossSalary -(standardExemption + pensionFund + personalExemption);
double tax =0;
if (taxableIncome <=15000){
tax = taxableIncome *0.15;
} else if (taxableIncome <=40000){
tax =2250+((taxableIncome -15000)*0.25);
} else {
tax =8460+((taxableIncome -40000)*0.35);
}
return tax;
}
int main(){
char mStatus;
int numOfPpl;
double grossSalary, pension, federalTax;
getData(mStatus, numOfPpl, grossSalary, pension);
federalTax = taxAmount(mStatus, numOfPpl, grossSalary, pension);
cout << fixed << showpoint << setprecision(2);
cout << "Marital Status is: "<<((mStatus =='M')? "Married" : "Single")<< endl;
cout << "Number of People is: "<< numOfPpl << endl;
cout << "Income earned is: $"<< grossSalary << endl;
cout << "Pension Plan Contribution is: $"<< pension << endl;
cout << "Taxable Income is: $"<<(grossSalary - pension -((mStatus =='M')?7000 : 4000)-(numOfPpl *((mStatus =='M')?1500 : 0)))<< endl;
cout << "The federal tax payable is: $"<< federalTax << endl;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!