trouble with, if statements

can someone please help me understand why my code keeps returning 0 for my taxBracket variable?

#include <iostream>
using namespace std;

int computeTax(int yearlyIncome)
{
int taxBracket;

if (0 <= yearlyIncome < 15100)
taxBracket = 10;
if (15100 <= yearlyIncome < 61300)
taxBracket = 15;
if (61300 <= yearlyIncome < 123700)
taxBracket = 25;
if (123700 <= yearlyIncome < 188450)
taxBracket = 28;
if (188450 <= yearlyIncome < 336550)
taxBracket = 33;
if (336550 <= yearlyIncome)
taxBracket = 35;

return taxBracket;
}


int main()
{

int yearlyIncome;
int taxBracket;

cout << "Income: ";
cin >> yearlyIncome;

computeTax(yearlyIncome);

cout << "Your tax bracket is: "
<< taxBracket
<< "\%"
<< endl;

return 0;
}
1
2
3
4
5
6
7
8
9
10
if (0 <= yearlyIncome < 15100)
taxBracket = 10;
if (15100 <= yearlyIncome < 61300)
taxBracket = 15;
if (61300 <= yearlyIncome < 123700)
taxBracket = 25;
if (123700 <= yearlyIncome < 188450)
taxBracket = 28;
if (188450 <= yearlyIncome < 336550)
taxBracket = 33;


You need to use logical operators when you are comparing different values.

&& "AND" Connects two expressions into one. Both expressions must be true for
the overall expression to be true.
|| "OR" Connects two expressions into one. One or both expressions must be
true for the overall expression to be true. It is only necessary for one to
be true, and it does not matter which.
! "NOT" The ! operator reverses the "truth" of an expression. It makes a true
expression false, and a false expression true.


Example:
1
2
if (temperature < 20 && minutes > 12)
cout << "The temperature is in the danger zone.";


1
2
if (temperature < 20 || temperature > 100)
cout << "The temperature is in the danger zone.";


1
2
if (!(temperature > 100))
cout << "You are below the maximum temperature.\n";

Topic archived. No new replies allowed.