Question

Ok so I've practically figured it out except two problems.
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
#include <iostream>
using namespace std;

int main ()
{
    
    float a, b, c, d, e, f, g (0);
    while (a > 0){
    cout << "How much is your yearly taxable income? ";
    cin >> a;
    if (a > 349700){
       a = a - 349700;
       b = a * .35;
       a = 349700;
       }
    if (a > 160850){
       a = a - 160850;
       c = a * .33;
       a = 160850;
       }
    if (a > 77100){
       a = a - 77100;
       d = a * .28;
       a = 77100;
       }
    if (a > 31850){
       a = a - 31850;
       e = a * .25;
       a = 31850;
       }
    if (a > 7825){
       a = a - 7825;
       f = a * .15;
       a = 7825;
       }
    if (a > 0){
       g = a * .10;
       }
    cout << b+c+d+e+f+g << endl;
}
    system("pause");
    return 0; 
}


I know my coding probably looks like crud but anyways my problems are:
1.)Lets say that the first value I input is 350,000. So it runs the first if statement and all the rest that follow. But then lets say I enter 200,000 next. It saves the value of b and adds it to the true value for 200,000. Is there a way I can 'clear' the variables back to 0 at the end of the loop maybe?

2.) It prints the correct values for any number I enter over 77,100 but gives me 5.34649e+036 for any value under that. Any help would be greatly appreciated.

Mike
Last edited on
The syntax for a switch/case is:
1
2
3
4
5
6
7
8
9
10
11
12
switch(/*arbitrary integral expression*/)
{
case /*constant*/:
//code here
break;

case /*constant*/:
//code here
break;

//And so on...
}


For inequalities, you need to use if. Switch only compares for equality between constant and arbitrary integral expression.
^^ new question
Last edited on
Topic archived. No new replies allowed.