[try Beta version]
Not logged in

 
Program to decide what Tax Bracket your are in.

May 13, 2013 at 2:29am
Trying to write a program in my class to display your tax bracket based off what your income is. When using this code it will only display return 33 as the answer reguardless of what I enter as the income. it always displays as follow
Income: I will enter lets say 5
Your tax bracket is 33%
when the correct response is
Your tax bracket is 10% please help?
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
#include <iostream>
using namespace std;

double computeTax()
{
   int income;

   {
      if (income > 336550)
         return (35);

      else if (income <= 336550 || income > 188450)
         return (33);

      else if (income <= 188450 || income > 123700)
         return (28);

      else if (income > 15100 || income <= 61300)
         return (15);
   }
}

int main()
{
   int income;
   cout << "Income: ";
   cin >> income;
   cout << "Your tax bracket is "
        << computeTax()
        << "%";
   return 0;
}
Last edited on May 13, 2013 at 2:32am
May 13, 2013 at 2:50am
try double computeTax(int income), this way, you use the value given to the function.

computeTax(income);
May 13, 2013 at 3:06am
I tried that and It appeared to work on a basic scale but now all it shows is
Your tax bracket is 33% reguardless of what number I enter as the income here is the code,

#include <iostream>
using namespace std;

double computeTax(int income)
{


{
if (income > 336550)
return (35);
else if (income > 188450 || income <= 336550)
return (33);
else if (income > 123700 || income <= 188450)
return (28);
else if (income > 61300 || income <= 123700)
return (25);
else if (income > 15100 || income <= 61300)
return (15);
else if (income > 0 || income <= 15100)
return (10);
}
}

int main()
{
int income;
cout << "Income: ";
cin >> income;
cout << "Your tax bracket is "
<< computeTax(income)
<< "%";
return 0;
May 13, 2013 at 3:24am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
double computeTax(int income)
{
if (income > 336550)
return (35);
else if (income > 188450 && income <= 336550)
return (33);
else if (income > 123700 && income <= 188450)
return (28);
else if (income > 61300 && income <= 123700)
return (25);
else if (income > 15100 && income <= 61300)
return (15);
else if (income > 0 && income <= 15100)
return (10);
}

Try this, I think your problem was that you were saying that the statement is true if income > 188450 or income <= 336550, which basically is saying that the whole statement is true when putting in the value of 5 into it.
May 13, 2013 at 4:04am
THANK YOU!!!
May 13, 2013 at 4:17am
wait a sec...why are you returning a double? You would be MUCH more accurate to return a const unsigned int. or a unsigned int or even just an int. because try this
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <iomanip>

int main( int argc , char** argv )
{
     const double a = 4;
     const unsigned int b = 4;
     std::cout << std::setprecision( 20 ) << a << std::endl;
     std::cout << std::setprecision( 20 ) << b << std::endl;
     return( 0 );
}


tell me which is more accurate =p
doubles are not necessarly 100% accurate 4 could really be like 3.9999999999999999999999
or 4.0000000000000000000001 depending on your IDE
Topic archived. No new replies allowed.