So I am trying to write a program where the user inputs their income then the program tells them which bracket they are in. I want a function that computes the tax bracket and then I want main to prompt the user for their income and tell them which tax bracket they are in.
I Thought I was on the right track with this but it won't compile and I am not sure exactly what I am doing wrong. I am just now becoming familiar with bool statements so I haven't quite got the hang of them yet.
Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
bool computeTax()
{
int income;
if income > 0 || < 1510
return 10%;
}
int main()
{
int income;
cout << "Income: ";
cin >> income;
computeTax();
return 0;
}
Why are you using bool datatype? Are trying to achieve something like this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int computeTax(int a) {
if (a > 0 || a < 1510)
return 10;
//else if {.... other tax bracket.
}
int main() {
int income;
cout << "Income: ";
cin >> income;
cout << computeTax(income) << "%";
return 0;
}
int computeTax(int a)
{
if (a > 0 || a < 15100)
return 10;
elseif (a > 15100 || a < 61300)
return 15;
elseif (a > 61300 || a < 123700)
return 25;
elseif (a > 123700 || a < 188450)
return 28;
elseif (a > 188450 || a < 336550)
return 33;
elseif (a > 336550 || a < no limit)
return 35;
}
int main()
{
int income;
cout << "Income: ";
cin >> income;
cout << "Your tax bracket is " << computeTax(income) << "%";
return 0;
}
How would I enter that there is no limit to how large the number is to fall in a 35% tax bracket? Would I just leave out the a < no limit?
Yes, you can omit it. Also, the way you have the conditions written if a = 15100 nothing would be returned. So in one of your statements you will want to have a >= 15100 or a <= 15100 depending on how the ranges work out. The same goes for 61300, 123700, etc.
oh ok that did the trick and makes a lot of sense. Would I be able to do it the reverse order that you have and have it work out the same way or is the order set? Thanks to all who helped out as always I have learned a lot from this.