tax calculator help

Hello. I am trying to write a program that calculates tax incrementally. The first 30000$ of income is not taxed. 30,000.01 to 50,000.00 is taxed 10% and so on. I need to tax each portion. For example, if someone made 110k, they would not be taxed for the first 30k, then would be taxed 10% for the next 20k, taxed 20% for the next 50k, and 30% for the last 10k.

Hello, I am very new to programming and wanted to get some help. I am using Xcode.
I have written the program but I'm having problems running it. When I run it, Xcode says Build Succeeded, but I am not prompted to enter an income. Instead, I get a bunch of green boxes with a white L in them followed by one of my variables. I get this for each variable, kind of like this: (the L is the green box)
[L] tax1 =(const double)0
[L] tax2 =(const double)0

I have tried not making my tax increment variables constants, I have tried not having the tax increment variables and just adding the increments when I calculate the tax --> taxedInc = ((income - 5000.00) * .20) + tax1
and a few other things, but I always get the same thing when I run the code.
I'm not sure what I am doing wrong and was wondering if someone could please help me with this. I would really appreciate it. Thank you.

I have put the increment values in the comments at the top of the program.

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
  //  incremental income
//  0 to $30,000.00                 0%
//  $30,000.01 t0 $50,000.00        10%
//  $50,000.01 to $100,000.00       20%
//  $100,000.01 to $200,000.00      30%
//  $200,000.01 to $250,000.00      35%
//  >$250,000.01                    40%
//

#include <iostream>

using namespace std;

int main()
{
        //taxe increments have been calculated
    
   const double tax1 = 2000.00;         // first tax increment 30k-50k
   const double tax2 = 10000.00;        // second increment 50k-100k
   const double tax3 = 30000.00;        // thrid increment 100k-200k
   const double tax4 = 17500.00;        // fourth increment 200k-250k
    
    double income;      //initial income
    double taxedInc;    //how much taxes are
    double afterTax;    // income after taxes
    
    

    cout << "What is your income? " << endl;    //get income
    cin >> income;
    
    if (income <= 30000.00)
    {
        cout << "Your tax rate is 0%, you have no deductions. " << endl;
        cout << "Your income is " << income << endl;
    }
    else if (income>=30000.01 && income<=50000.00)
    {
        taxedInc = (income - 30000.00) * .10;       //calculates tax amount
        afterTax = income - taxedInc;
        
        cout << "Your income before taxes is " << income << "." << endl;
        cout << "Your income after deduction is " << afterTax << "." << endl;
        cout << "Your deducted amount is " << taxedInc << "." << endl;
        
    }
    else if (income>=50000.01 && income<=100000.01)
    {
        taxedInc = ((income - 50000.00) * .20) + tax1;      //calculates tax 
        afterTax = (income - taxedInc);
        
        cout << "Your income before taxes is " << income << "." << endl;
        cout << "Your income after taxes is " << afterTax << "." << endl;
        cout << "Your deducted amount is " << taxedInc << "." << endl;
    }
    else if (income>=100000.01 && income<=200000.00)
    {
        taxedInc = ((income - 100000.00) * .30) + tax1 + tax2; //calculates tax 
        afterTax = (income - taxedInc);
        
        cout << "Your income before taxes is " << income << "." << endl;
        cout << "Your income after taxes is " << afterTax << "." << endl;
        cout << "Your deducted amount is " << taxedInc << "." << endl;
    }
    else if (income>=200000.01 && income<=250000.00)
    {
        taxedInc =((income - 200000.00) * .35) + tax1 + tax2 + tax3;        //finds tax amount
        afterTax = (income -taxedInc);
        
        cout << "Your income before taxes is " << income << "." << endl;
        cout << "Your income after taxes is " << afterTax << "." << endl;
        cout << "Your deducted amount is " << taxedInc << "." << endl;
    }
    else if (income>250000.00)
    {
        taxedInc = ((income - 250000.00) * .40) + tax1 + tax2 + tax3 + tax4;        //finds tax amount
        afterTax = (income - taxedInc);
        
        cout << "Your income before taxes is " << income << "." << endl;
        cout << "Your income after taxes is " << afterTax << "." << endl;
        cout << "Your deducted amount is " << taxedInc << "." << endl;
    }
    else
        cout << "You have entered an unuseable number. Please restart the program and enter a positive number " << endl;
    
    return 0;
}
Try running the program in a terminal window. It runs okay for me.

Here are some comments on your code.

Nice job with the comments! They give an overview of the code which is just what they should do.

taxedInc is a poorly named variable. It sounds like it's the amount of income subject to tax when it truth it's the tax amount.

There's a lot of repeated code to print out the results. Consider having one block (or function) that computes the tax and then a separate block that prints the results. This follows the general goal of separating computation from presentation.

Consider what happens if a tax bracket changes or if a bracket is added or removed. What changes do you have to make to the code? With this code, the changes are significant: The initial comment, the tax variables at lines 18-21, the if/else statements that find the bracket and the code that computes the tax. Ideally you'd have to change just one thing and the code would still work. If you have some time, you might want to think about how to do that. A word of caution though: save your working code before trying to improve it. You don't want to turn working code into a big mess and find yourself up against a deadline.
Topic archived. No new replies allowed.