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.


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
	

    #include <iostream>
    #include <string>
    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.