I am new to C++ and would like to know why my code isn't working. Whenever i run it, i keep getting 'Tax payable = 0' no matter what value i input for my annual income variable 'aninc' Where is my error please? Find attached the question.
Here is my code
#include <iostream>
using namespace std;
int main() {
int aninc, dep, tax;
cout << "Enter your annual income: ";
cin >> aninc;
cout << "Enter how many dependants you have: ";
cin >> dep;
if (dep < 0) {
cout << "Invalid input! Number of dependants cannot be negative.";
} else if (dep >= 0) {
if (dep > 3) {
dep = 3;
}
switch (dep) {
case 0:
aninc = aninc - 255000;
break;
case 1:
aninc = aninc - 325000;
break;
case 2:
aninc = aninc - 395000;
break;
case 3:
aninc = aninc - 455000;
break;
}
if (aninc > 70000) {
tax = ((15 / 100) * 50000) + ((20 / 100) * (70000 - 50000)) +
((25 / 100) * (aninc - 70000));
}
if (aninc > 50000 && aninc < 70000) {
tax = ((15 / 100) * 50000) + ((20 / 100) * (aninc - 50000));
}
if (aninc <= 50000) {
tax = ((15 / 100) * aninc);
}
cout << "Tax payable: " << tax << endl;
}
return 0;
}
I have the following C++ question where i have to implement a switch statement.