Hello I am writing a program to return your income and put it into a tax bracket I haven't been able to find out why it doesn't go into the correct bracket.
int computetax()
{
int income;
int bracket;
if (income > 0 && income < 15100)
bracket = 10;
if (income > 15100 && income < 61300)
bracket = 15;
if (income > 61300 && income < 123700)
bracket = 25;
if (income > 123700 && income < 188450)
bracket = 28;
if (income > 188450 && income < 336550)
bracket = 33;
if (income > 336550)
bracket = 35;
return bracket;
}
int main()
{
int income;
int bracket = computetax();
// prompt for income
cout << "income: ";
cin >> income;
// prompt for bracket
if (computetax());
cout << "Your tax bracket is ";
cout << bracket;
cout << "%";
cout << "\n";
First, you call computetax() before even asking for the income, so you will be operating on a garbage value. Second, you don't actually pass income into computetax() so it operates on its own (uninitialized) copy that is a garbage value.
You might also want to note that your if statements don't cover if your income is exactly on a boundary (123700, 188450, etc.).