budget

I'm trying to create a monthly budget and inside I have a function that completes what tax bracket they are in. For some reason .10 is being multiplied by their monthly income, Can you look at my code and see why it's doing that? And how I can actually get accurate results for their actual tax bracket.

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
  float computeTax (float monthlyIncome)
{
   cout.setf(ios::fixed); //no scientific notation
   cout.setf(ios::showpoint); //always show the decimal
   cout.precision(2); //two digits for showing the price

   //declare the variables
   float yearlyIncome = monthlyIncome * 12;
   float yearlyTax;

   if (0 <= yearlyIncome < 15100)
      yearlyTax = yearlyIncome * .1;

   else if (15100 <= yearlyIncome < 61300)
      yearlyTax = 1510 + .15 * (yearlyIncome - 15100);

   else if (61300 <= yearlyIncome < 123700)
      yearlyTax = 8440 + .25 * (yearlyIncome - 61300);

   else if (123700 <= yearlyIncome < 188450)
      yearlyTax = 24040 + .28 * (yearlyIncome - 123700);

   else if (188450 <= yearlyIncome < 336550)
      yearlyTax = 42170 + .33 * (yearlyIncome - 188450);

   else if (336550 <= yearlyIncome)
      yearlyTax = 91043 + .35 * (yearlyIncome - 336500);

float monthlyTax = yearlyTax / 12;

   return monthlyTax;
}
What did you pass as monthlyIncome?
Nevermind. You cannot chain logical expressions like you would in math.
(0 <= yearlyIncome < 15100) would be computed like so:
lets say yearlyIncome = 20000
It first checks if yearlyIncome is bigger or equal to 0. That will return true/1. Then it checks if 1 is smaller than 15100, which it always is.

EDIT:
The correct way would be:
if(yearlyIncome >= 0 && yearlyIncome < 15100)
Last edited on
Thank you so much! Still kinda a noob at this
Topic archived. No new replies allowed.