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?
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;
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.
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 )
{
constdouble a = 4;
constunsignedint 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