If wont work properly

Im trying to make a tax program and for some reason if the income is < 100000 everything works fine but as soon as its more than that it gives me the wrong answer. It reads the first if statement then if its false goes to the 2nd but if income > 100000 it doesnt go to the next if but instead just goes straight to the output.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cout << "Enter yearly income amount (0.0 to quit): $ ";
		cin >> income;

		if (income <= 50000)				//500 max tax
			tax = income * 0.01;
		else if (income > 50000 || income <= 75000)	//500 + max 500
			tax = 500 + 0.02 * (income - 50000);
		else if (income > 75000 || income <= 100000)	//500 + 500 + max 750
			tax = 1000 + 0.03 * (income - 75000);
		else if (income > 100000 || income <= 250000)	//500 + 500 + 750 + max 6000
			tax = 1750 + 0.04 * (income - 100000);
		else if (income > 250000 || income <= 500000)	//500 + 500 + 750 + 6000 + max 12500
			tax = 7750 + 0.05 * (income - 250000);
		else if (income > 500000)			//500 + 500 + 750 + 6000 + 12500 + (income - 500000)
			tax = 20250 + 0.06 * (income - 500000); 

		cout << "The U.S. 1913 income tax = $" << tax << endl;
if (income > 50000 || income <= 75000)


This is always going to be true because every number is either greater than 50000 OR less than 75000. You probably meant &&

But you shouldn't be using && either. Let else do the work for you here. If you do an 'else', you know the previous 'if' condition is false. Therefore...

1
2
3
4
if(income <= 50000)
   ...
else if(income <= 75000)  // <- don't check > 50000, we already know the 
      // income is > 50000 because of the 'else' here. 



Code duplication is bad.
Last edited on
Topic archived. No new replies allowed.