fixed.

thanks
Last edited on
I'm not a fan of your indenting. Also, there are better ways to do the loops you have.

Before:
1
2
3
4
5
6
if(taxableIncome<=7550){taxAmt=(taxableIncome*0.10);}
else if(taxableIncome>=7551 && taxableIncome<=30650){taxAmt=taxableIncome*0.15;}
else if(taxableIncome>=30651 && taxableIncome<=74200){taxAmt=taxableIncome*0.25;}
else if(taxableIncome>=74201 && taxableIncome<=154800){taxAmt=taxableIncome*0.28;}
else if(taxableIncome>=154801 && taxableIncome<=336550){taxAmt=taxableIncome*0.33;}
else if(taxableIncome>=336551){taxAmt=taxableIncome*0.35;}


After:
1
2
3
4
5
6
if(taxableIncome > 336550) taxAmt = taxableIncome * .35;
else if(taxableIncome > 154800) taxAmt = taxableIncome * .33;
else if(taxableIncome > 74200) taxAmt = taxableIncome * .28;
else if(taxableIncome > 30650) taxAmt = taxableIncome * .25;
else if(taxableIncome > 7550) taxAmt = taxableIncome * .15;
else taxAmt = taxableIncome *.1;


or
taxAmt = taxableIncome * (taxableIncome > 336550 ? .35 : taxableIncome > 154800 ? .33 : taxableIncome > 74200 ? .28 : taxableIncome > 30650 ? .25 : taxableIncome > 7550 ? .15 : .1);



EDIT:

Please do not remove code after posting it, in case others have the same issue in the future.

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
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
                    
int main() {
    // Declare variables
    int statusCode = 0;
    float taxableIncome = 0.0, taxAmt = 0.0;
    
    string filingStatus[] = {
        "Single Filer",
        "Married Filing Jointly",
        "Married Filing Separately",
        "Head of Household"
    };

    //Input status code
    do{
        cout << "\nStatus Code\n"
            << "1:Single\n"
            << "2:Married Filing Jointly\n"
            << "3:Married Filing Separately\n"
            << "4:Head of Household\n"
            << "9:End Process\n\n"
            << "Enter the appropriate status code number: ";
        cin >> statusCode;
        if (statusCode == 9) {
            return 0;
        }
    } while(statusCode < 0 || statusCode > 4);//stays in loop until input is correct

    //Input taxable income
    do{
        cout << "Enter a taxable income (at least $500): $";
        cin >> taxableIncome;
    } while(taxableIncome < 500);//keeps user in loop until amount is greater than 500

    //Calc. the tax owed from results of status code and taxable income
    switch(statusCode) {
        //single
        case 1:
            if(taxableIncome<=7550){taxAmt=(taxableIncome*0.10);}
            else if(taxableIncome<=30650){taxAmt=taxableIncome*0.15;}
            else if(taxableIncome<=74200){taxAmt=taxableIncome*0.25;}
            else if(taxableIncome<=154800){taxAmt=taxableIncome*0.28;}
            else if(taxableIncome<=336550){taxAmt=taxableIncome*0.33;}
            else if(taxableIncome>=336551){taxAmt=taxableIncome*0.35;}
            break;
        //married filing jointly
        case 2:
            if(taxableIncome<=15100){taxAmt=(taxableIncome*0.10);}
            else if(taxableIncome<=61300){taxAmt=taxableIncome*0.15;}
            else if(taxableIncome<=123700){taxAmt=taxableIncome*0.25;}
            else if(taxableIncome<=188450){taxAmt=taxableIncome*0.28;}
            else if(taxableIncome<=336550){taxAmt=taxableIncome*0.33;}
            else if(taxableIncome>=336551){taxAmt=taxableIncome*0.35;}
            break;
        //married filing separately
        case 3:
            if(taxableIncome<=7550){taxAmt=(taxableIncome*0.10);}
            else if(taxableIncome<=30650){taxAmt=taxableIncome*0.15;}
            else if(taxableIncome<=61850){taxAmt=taxableIncome*0.25;}
            else if(taxableIncome<=94225){taxAmt=taxableIncome*0.28;}
            else if(taxableIncome<=168275){taxAmt=taxableIncome*0.33;}
            else if(taxableIncome>=168276){taxAmt=taxableIncome*0.35;}
            break;
        //head of household
        case 4:
            if(taxableIncome<=10750){taxAmt=(taxableIncome*0.10);}
            else if(taxableIncome<=41050){taxAmt=taxableIncome*0.15;}
            else if(taxableIncome<=106000){taxAmt=taxableIncome*0.25;}
            else if(taxableIncome<=171650){taxAmt=taxableIncome*0.28;}
            else if(taxableIncome<=336550){taxAmt=taxableIncome*0.33;}
            else if(taxableIncome>=336551){taxAmt=taxableIncome*0.35;}
            break;
    }   

    cout << setiosflags(ios::fixed)
         << setprecision(2)
         << "\nFiling status: "
         << filingStatus[statusCode-1]
         <<"\nTaxable income: $"
         << taxableIncome
         <<"\nTax amount: $"
         << taxAmt << endl;

    return 0;
}
(indented code provided by Smac89, the original had 0 indents)
Last edited on
Here is one way (fixing indenting mostly):
http://cpp.sh/6s52

Another way(building on the first):
http://cpp.sh/7326
Last edited on
Topic archived. No new replies allowed.