Hello! The homework question is this one: write a program tht can be used to calculate the federal tax. The tax calculated as follows: For single peopl, the standard exemption is $4000; for married people, the standard exemption is $7000. A person can also put up to 6% of his or her gross standard income in a pension plan. The tax rates are as follows: If the the taxable income is
1) Between $0 and $15000, the tax rate is 15%
2)between $1500 and $40000, the tax is $2250 plus 25% of the taxable income over $1500
3)Over $40,000, the tax is $8460 plus 35% of the taxable income over $40000
Prompt the user to enter the following information:
4)Martial status
5)If the marital status is "married", ask for the number of children under the age of 14
6)Gross salary(if the martial status is "married" and both spouses have income, enter the combined salary.)
7)percentage of gross income contributed to a pension fund.
The program must consist of at leat the following functions:
a) function getData: this function asks the user to enter the relevant data.
b) function taxAmount: this function computes and returns the tax owned.
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 $1500 per person.
And this is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <process.h>
double taxAmount(double salary, double kid, double pension, double status);
void getData();
using namespace std;
int main()
{
cout << "This is a program to calculate your federal taxes." << endl;
cout << "Welcome! Please enter in the required information!" << endl;
getData();
system("pause");
return 0;
}
void getData()
{
char martialStatus;
char pensionChoice;
double grossSalary;
double pensionPercentage;
double child;
double mstatusNum;
cout << "What is your Martial Status?" << endl;
cout << "Enter S/s for Single, or M/m for Married: " << endl;
cin >> martialStatus;
if (martialStatus == 'S' || martialStatus == 's')
{
mstatusNum = 1;
cout << "Please enter in your salary: " << endl;
cin >> grossSalary;
cout << "Enter in number of kids under the age of 14: " << endl;
cin >> child;
cout << "Would you like to contribute up to 6% of your Salary to a Pension Plan?" << endl;
cout << "Enter Y/y for yes or N/n for No: " << endl;
cin >> pensionChoice;
if (pensionChoice == 'Y' || pensionChoice == 'y')
{
cout << "Enter in a number between 1-6 of how high: ";
cin >> pensionPercentage;
while (pensionPercentage < 1 || pensionPercentage > 6)
{
cout << "That is not the correct number, please enter in a number between 1-6: " << endl;
cin >> pensionPercentage;
}
}
else
{
pensionPercentage = 0;
}
cout << "We will now calculate your federal taxes..." << endl;
cout << "Your taxes are: " << taxAmount(grossSalary, child, pensionPercentage, mstatusNum) << endl;
}
else
{
mstatusNum = 2;
cout << "Please enter in the combined salary of you and your spouse: " << endl;
cin >> grossSalary;
cout << "Enter in number of kids under the age of 14: " << endl;
cin >> child;
cout << "Would you like to contribute up to 6% of your Salary to a Pension Plan?" << endl;
cout << "Enter Y/y for yes or N/n for No: " << endl;
cin >> pensionChoice;
if (pensionChoice == 'Y' || pensionChoice == 'y')
{
cout << "Enter in a number between 1-6 of how high: ";
cin >> pensionPercentage;
while (pensionPercentage < 1 || pensionPercentage > 6)
{
cout << "That is not the correct number, please enter in a number between 1-6: " << endl;
cin >> pensionPercentage;
}
}
else
{
pensionPercentage = 0;
}
cout << "We will now calculate your federal taxes..." << endl;
cout << "Your taxes are: " << taxAmount(grossSalary, child, pensionPercentage, mstatusNum) << endl;
}
}
double taxAmount(double salary, double kid, double pension, double status)
{
double const sinExem = 4000.00;
double const marExem = 7500.00;
double const rate1 = 0.15;
double const rate2 = 0.25;
double const rate3 = 0.35;
double const tax1 = 2250.00;
double const tax2 = 8460.00;
double federalTaxes;
double penPercent = pension / 100;
double taxableAmount;
double penTotal = salary * penPercent;
if (status == 1)
{
taxableAmount = salary - (1500.00 * kid) - penTotal - sinExem;
}
else if (status == 2)
{
taxableAmount = salary - (1500.00 * kid) - penTotal - marExem;
}
if (taxableAmount >= 0 || taxableAmount <= 15000)
{
federalTaxes = taxableAmount * rate1;
}
else if (taxableAmount >= 15001 || taxableAmount <= 40000)
{
federalTaxes = (taxableAmount * rate2) + tax1;
}
else if (taxableAmount >= 40001)
{
federalTaxes = (taxableAmount * rate3) + tax2;
}
return federalTaxes;
}
|
While this is running and I am getting the answers I am wanting I was having issues before doing any user input error check to make sure the user input valid characters such as 'M' or 'S' for married or 'Y' or 'N' for if they want to calculate their pension, and allowing them to re-enter data. The structure of the while loop was as such:
1 2 3 4 5 6
|
while (pensionChoice != 'Y' || pensionChoice != 'y' || pensionChoice != 'N' || pensionChoice != 'n')
{
cout << "That is not a valid answer, please enter again: " << endl;
cin >> pensionChoice;
}
|
typically what happens is if I enter in any of the correct input, it keeps executing that while loop the one for married has a similar structure. Any help appreciated!