Help me find my mistakes PLEASE!

Hi guys!
Really need some help with my school project!
I needed to create a program to compute federal personal income taxes.
Requirements that I am to follow:
"Your program should be modular, that is small blocks of code. (Later in the semester when we encounter functions, you will see how handy modular development can be.) You are to follow these specifications as closely as possible. You should have code blocks that do the following:
1. Input status code. You should use a do/while loop to control the input logic. You are to keep the user in the loop until the input is correct. You are to ensure that the status codes are as specified above.
2. Input taxable income. As in step 1, you are to use a do/while loop for this logic. You are to keep the user in the loop until the input is valid.Calculate the tax owned as a result of status code and taxable income. You are to use a switch statement for the appropriate logic for each status code. You should manually calculate several cases to ensure your program is performing correctly.
3. Display the results of the calculation step. You are to output the status code, the string description of the status code, the taxable income, and the total tax amount. You are to use appropriate formatting of the output.
4. You main loop should be a while loop that repeat steps 1 through 4 until the user enters a status code of 9 that will terminate the job."

What I came up with:

//***************************************************
//This Pogram computes federal personal income taxes.
//The filing status and income are input by the User.
//***************************************************

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int statusCode; //variable declaration for input
float taxableIncome;
float taxAmt;


//Prompt the User to enter filing status and income


while (statusCode !=9)
{
do
{
cout << "Enter your filing status by a number 1 through 4 where: "<< endl;
cout << " 1 = single" << endl;
cout << " 2 = married filing jointly" << endl;
cout << " 3 = married filing separately" << endl;
cout << " 4 = head of household" << endl;
cout << "Enter 9 if you want to end the process" << endl;
cin >> statusCode;

if (statusCode != 1 && statusCode != 2 && statusCode != 3 && statusCode != 4 && statusCode != 9)
cout << "Your filing status must be 1 through 4 or 9 if you want to end this program" << endl;

} while (statusCode != 1 && statusCode != 2 && statusCode != 3 && statusCode != 4 && statusCode != 9);

do
{
cout << "Now enter your yearly imcome that must be more than $3000. Example: 96230 if you made $96230" << endl;
cin >> taxableIncome;

if (taxableIncome <= 3000)
cout << "Your taxable income must be more than $3000" << endl;

//Filing status 1 - Single

switch (statusCode = 1)
{
case 1: if ( statusCode = 1 && taxableIncome <= 7550)
taxAmt = taxableIncome * 0.12;
break;
case 2: if ( statusCode = 1 && taxableIncome >= 7551 && taxableIncome <= 30650)
taxAmt = taxableIncome * 0.16;
break;
case 3: if ( statusCode = 1 && taxableIncome >= 30651 && taxableIncome <= 74200)
taxAmt = taxableIncome * 0.20;
break;
case 4: if ( statusCode = 1 && taxableIncome >= 74201 && taxableIncome <= 154800)
taxAmt = taxableIncome * 0.28;
break;
case 5: if ( statusCode = 1 && taxableIncome >= 154801 && taxableIncome <= 336550)
taxAmt = taxableIncome * 0.32;
break;
case 6: if ( statusCode = 1 && taxableIncome >= 336551)
taxAmt = taxableIncome * 0.40;
break;
}

//Filing status 2 - Married filing jointly

switch (statusCode = 2)
{
case 1: if ( statusCode = 2 && taxableIncome <= 15100)
taxAmt = taxableIncome * 0.12;
break;
case 2: if ( statusCode = 2 && taxableIncome >= 15101 && taxableIncome <= 61300)
taxAmt = taxableIncome * 0.16;
break;
case 3: if ( statusCode = 2 && taxableIncome >= 61301 && taxableIncome <= 123700)
taxAmt = taxableIncome * 0.20;
break;
case 4: if ( statusCode = 2 && taxableIncome >= 123701 && taxableIncome <= 188450)
taxAmt = taxableIncome * 0.28;
break;
case 5: if ( statusCode = 2 && taxableIncome >= 188451 && taxableIncome <= 336550)
taxAmt = taxableIncome * 0.32;
break;
case 6: if ( statusCode = 2 && taxableIncome >= 336551)
taxAmt = taxableIncome * 0.40;
break;
}

//Filing status 3 - Married filinf separately

switch (statusCode = 3)
{
case 1: if ( statusCode = 3 && taxableIncome <= 7550)
taxAmt = taxableIncome * 0.12;
break;
case 2: if ( statusCode = 3 && taxableIncome >= 7551 && taxableIncome <= 30650)
taxAmt = taxableIncome * 0.16;
break;
case 3: if ( statusCode = 3 && taxableIncome >= 30651 && taxableIncome <= 61850)
taxAmt = taxableIncome * 0.20;
break;
case 4: if ( statusCode = 3 && taxableIncome >= 61851 && taxableIncome <= 94225)
taxAmt = taxableIncome * 0.28;
break;
case 5: if ( statusCode = 3 && taxableIncome >= 94226 && taxableIncome <= 168275)
taxAmt = taxableIncome * 0.32;
break;
case 6: if ( statusCode = 3 && taxableIncome >= 168276 )
taxAmt = taxableIncome * 0.40;
break;
}

//Filing status 4 - Head of the Household

switch (statusCode = 4)
{
case 1: if ( statusCode = 4 && taxableIncome <= 10750)
taxAmt = taxableIncome * 0.12;
break;
case 2: if ( statusCode = 4 && taxableIncome >= 10751 && taxableIncome <= 41050)
taxAmt = taxableIncome * 0.16;
break;
case 3: if ( statusCode = 4 && taxableIncome >= 41051 && taxableIncome <= 106000)
taxAmt = taxableIncome * 0.20;
break;
case 4: if ( statusCode = 4 && taxableIncome >= 106000 && taxableIncome <= 171650)
taxAmt = taxableIncome * 0.28;
break;
case 5: if ( statusCode = 4 && taxableIncome >= 171651 && taxableIncome <= 336550)
taxAmt = taxableIncome * 0.32;
break;
case 6: if ( statusCode = 4 && taxableIncome >= 336551 )
taxAmt = taxableIncome * 0.40;
break;
}

cout << "Filing status: " << statusCode << endl;
cout << "Taxable income: " << taxableIncome << endl;
cout << "Tax amount: " << taxAmt << endl;

} while (taxableIncome <= 3000);

system("pause"); //pause system to see the results
return 0;

}

} //main function ends


It runs but showing: "Run-Time Check Failure #3 - The variable 'statusCode' is being used without being initialized." and when I put status to check my program it is showing statusCode as 0. Any idea why? ! I can't figure out what I am doing wrong =(

Thank you in advance!
int statusCode; //variable declaration for input
statusCode has a random value. It might even has the value 9 and your program won't do anything at all. Best practice is to give all variables a value when you create them. int statusCode = 0;
closed account (48T7M4Gy)
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
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int statusCode = 0; //variable declaration for input
    double taxableIncome = 0.0;
    double taxAmt = 0.0;
    
    
    //Prompt the User to enter filing status and income
    do
    {
        cout << "Enter your filing status by a number 1 through 4 where: "<< endl;
        cout << " 1 = single" << endl;
        cout << " 2 = married filing jointly" << endl;
        cout << " 3 = married filing separately" << endl;
        cout << " 4 = head of household" << endl;
        cout << "Enter 9 if you want to end the process" << endl;
        cin >> statusCode;
        if(statusCode == 9){return 0;};
        
        
        
    } while (
             cout << "Filing status must be 1 - 4, 9 to quit\n" &&
             (statusCode < 1 || statusCode > 4)
             );
    
    
    
    do
    {
        cout << "Enter yearly imcome - must be more than $3000\n";
        cin >> taxableIncome;
        
    } while (
             cout << "*** Your taxable income must be more than $3000\n" &&
             taxableIncome <= 3000
             );
    
    
    
    switch (statusCode)
    {
        case 1:
            if (taxableIncome <= 7550)
                taxAmt = taxableIncome * 0.12;
            else if ( taxableIncome >= 7551 && taxableIncome <= 30650)
                taxAmt = taxableIncome * 0.16;
            else if ( taxableIncome >= 30651 && taxableIncome <= 74200)
                taxAmt = taxableIncome * 0.20;
            else if ( taxableIncome >= 74201 && taxableIncome <= 154800)
                taxAmt = taxableIncome * 0.28;
            else if ( taxableIncome >= 154801 && taxableIncome <= 336550)
                taxAmt = taxableIncome * 0.32;
            else
                taxAmt = taxableIncome * 0.40;
            break;
            
        case 2:
            if (taxableIncome <= 15100)
                taxAmt = taxableIncome * 0.12;
            else if (taxableIncome >= 15101 && taxableIncome <= 61300)
                taxAmt = taxableIncome * 0.16;
            else if ( taxableIncome >= 61301 && taxableIncome <= 123700)
                taxAmt = taxableIncome * 0.20;
            else if (taxableIncome >= 123701 && taxableIncome <= 188450)
                taxAmt = taxableIncome * 0.28;
            else if ( taxableIncome >= 188451 && taxableIncome <= 336550)
                taxAmt = taxableIncome * 0.32;
            else
                taxAmt = taxableIncome * 0.40;
            break;
            
        case 3:
            if (taxableIncome <= 7550)
                taxAmt = taxableIncome * 0.12;
            else if (taxableIncome >= 7551 && taxableIncome <= 30650)
                taxAmt = taxableIncome * 0.16;
            else if ( taxableIncome >= 30651 && taxableIncome <= 61850)
                taxAmt = taxableIncome * 0.20;
            else if ( taxableIncome >= 61851 && taxableIncome <= 94225)
                taxAmt = taxableIncome * 0.28;
            else if (taxableIncome >= 94226 && taxableIncome <= 168275)
                taxAmt = taxableIncome * 0.32;
            else
                taxAmt = taxableIncome * 0.40;
            break;
            
        case 4:
            if (taxableIncome <= 10750)
                taxAmt = taxableIncome * 0.12;
            else if (taxableIncome >= 10751 && taxableIncome <= 41050)
                taxAmt = taxableIncome * 0.16;
            else if (taxableIncome >= 41051 && taxableIncome <= 106000)
                taxAmt = taxableIncome * 0.20;
            else if (taxableIncome >= 106000 && taxableIncome <= 171650)
                taxAmt = taxableIncome * 0.28;
            else if (taxableIncome >= 171651 && taxableIncome <= 336550)
                taxAmt = taxableIncome * 0.32;
            else
                taxAmt = taxableIncome * 0.40;
            break;
            
        default:
            cout << "Wrong status code was entered\n";
    }
    
    
    
    cout << " Filing status $ " << statusCode << endl;
    cout << "Taxable income $ " << taxableIncome << endl;
    cout << "    Tax amount $ " << taxAmt << endl;
    
    
    
    system("pause");
    return 0;
} //main function ends 
Last edited on
Topic archived. No new replies allowed.