### Federal Tax Program Issue

I can get this program to run, but it always says that it returns a tax of 0. Any idea as to why that is?

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

- Between \$0 & \$15,000, the tax rate is 15%
- Between \$15,001 and \$40,000, the tax is \$2,250 plus 25% of the taxable income over \$15,000
- Over \$40,000, the tax is \$8,460 plus 35% of the taxable income over \$40,000

The user should enter:
- Marital Status
- If the martial status is "married" ask for the number of children under the age of 14
- Gross salary (If the marital status is "married" and both spouses have income, enter the combined salary
- Percentage of gross income contributed to a pension fund.

The program must consist of at least 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 owed

To calculate the taxable income, subtract the sum of the standard exemption, the amount contributed to a pension plan, and the person exemption, which is \$1,500 per person.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 #include #include using namespace std; int getNumChildren(); double taxAmount(); int main () { int numPerson, standardExemption, tax; double salary, amtInPension, amtdeducted; void getData(); getData(); double taxAmount(int numPerson, double salary, double amtdeducted, int standardExemption); amtdeducted = salary - amtInPension; tax = taxAmount(numPerson, salary, amtInPension,standardExemption); cout << "The tax is: " << tax << endl; return 0; } void getData() { char maritalStatus, answer; int numChildren; double salary; int numPerson; double standardExemption; double grossIncome; double pension; cout << "What is your marital status? M = Married & S = Single : "; cin >> maritalStatus; cout << endl; if (maritalStatus == 'm' || maritalStatus == 'M') { numChildren = getNumChildren(); cout << "Do both spouses earn income? Y = Yes & N = No : "; cin >> answer; cout << endl; if (answer == 'y' || answer == 'Y' ) { cout << "Enter your combined salary: "; cin >> grossIncome; cout << endl; } else { cout << "Enter your salary: "; cin >> grossIncome; cout << endl; } numPerson = 2 + numChildren; } else { cout << "Please enter your salary: "; cin >> grossIncome; cout << endl; numPerson = 1; } } int getNumChildren() { int children; cout << "Please enter number of Children under the age of 14: "; cin >> children; cout << endl; return children; } double taxAmount(int numPerson, double salary, double amtdeducted, int standardExemption) { double taxableIncome, marginalIncome, marginTax; int tax; int baseTax, totalTax; taxableIncome = salary - (1500.00 * numPerson) - amtdeducted - standardExemption; if (tax >= 0 || tax <= 15000) { marginTax =.15 * taxableIncome; totalTax = marginTax; } else if (tax >= 15001 || tax <= 40000) { marginalIncome = taxableIncome - 15000; marginTax = .25 * taxableIncome; baseTax = 2250; totalTax = baseTax + marginTax; } else if (tax > 40000) { marginalIncome = taxableIncome - 40000; marginTax = .35 * taxableIncome; baseTax = 8460; totalTax = baseTax + marginTax; } return(totalTax); }
 ... but it always says that it returns a tax of 0. Any idea as to why that is?

Yes, because of Line 99. 0 - (1500.00 * 0) - 0 - 0 is going to equal 0 every time.

You seem to be confused about how variable scope works, just naming a variable the same thing within a different function isn't enough to preserve it's value. You also seem to have a habit of trying to evaluate variables before they are set to any kind of value. Have you read the tutorial on this site yet? It covers all of these things and will give you a pretty good understanding of where you're going wrong. http://www.cplusplus.com/doc/tutorial/
Last edited on
Topic archived. No new replies allowed.