Code not going off of user input

Hi, in my code I ask the user to input 2 different values, and have if statements set up based on what they ask for. But for no matter what value I put in, it does the same calculation and doesnt follow the if statements. How can I fix this?

int main()
{

std::cout << std::fixed;
std::cout << std::setprecision(2);
bool flag = true;
while (flag){

char S, J, F, H;
cout << "Please enter your filing status";
cout << "\n Enter S for Single Fillers,";
cout << "\n J for married filing Jointly,";
cout << "\n F for married filing separately, or";
cout << "\n H for head of household";
char status;
cout << "\n Status: "; cin >> status;

int taxable = 0;
double owedTax = 0;
if (status == S);
cout << "Please enter your income: "; int income;
cin >> income;
taxable = income - STD_DEDS;
if (taxable <= SINGLE10)
owedTax = taxable * PER10;
if (taxable >= SINGLE10 && taxable <= SINGLE15)
owedTax = SINGLE10* PER10 + (taxable - SINGLE10)*PER15;
if (taxable >= SINGLE15 && taxable <= SINGLE25)
owedTax = SINGLE10*PER10 + (SINGLE15 - SINGLE10)*PER15 + (taxable - SINGLE15)*PER25;;
if (taxable>= SINGLE25 && taxable <= SINGLE28)
owedTax = SINGLE10*PER10 + (SINGLE15 - SINGLE10)*PER15 + (SINGLE28 - SINGLE25)*PER25+(taxable - SINGLE25)*PER28;
if (taxable >= SINGLE28 && taxable <= SINGLE33)
owedTax = SINGLE10*PER10 + (SINGLE15-SINGLE10)*PER15 + (SINGLE28 - SINGLE25)*PER25+ (SINGLE33 - SINGLE28)*PER28+ (taxable - SINGLE28)*PER33;
if (taxable >= SINGLE33 && taxable <= SINGLE35)
owedTax = SINGLE10*PER10 + (SINGLE15-SINGLE10)*PER15 + (SINGLE28-SINGLE25)*PER25+(SINGLE33 - SINGLE28)*PER28 + (SINGLE35-SINGLE33)*PER33 + (taxable-SINGLE33)*PER35;
if (taxable >= SINGLE35 && taxable <= SINGLE39)
owedTax = SINGLE10*PER10 + (SINGLE15-SINGLE10)*PER15 + (SINGLE28-SINGLE25)*PER25+(SINGLE33-SINGLE28)*PER28 + (SINGLE35-SINGLE33)*PER33 + (SINGLE39-SINGLE35)*SINGLE35+(taxable-SINGLE35)*PER39;
cout << "Your tax is: $" << owedTax << endl;


return 0;

{
if (status == J);
cout << "Please enter your income: "; int income;
cin >> income;
taxable = income - STD_DEDJ;
if (taxable > J39)
owedTax = J10*PER10 + (J15-J10)*PER15 + (J28-J25)*PER25+(J33-J28)*PER28 + (J35-J33)*PER33 + (J39-J35)*J35+(taxable-J35)*PER39;
if (owedTax <= J35)
owedTax = J10*PER10 + (J15-J10)*PER15 + (J28-J25)*PER25+(J33 - J28)*PER28 + (J35-J33)*PER33 + (taxable-J33)*PER35;
if (owedTax <= J33)
owedTax = J10*PER10 + (J15-J10)*PER15 + (J28 - J25)*PER25+ (J33 - J28)*PER28+ (taxable - J28)*PER33;
if (owedTax <= J28)
owedTax = J10*PER10 + (J15 - J10)*PER15 + (J28 - J25)*PER25+(taxable - J25)*PER28;
if (owedTax <= J25)
owedTax = J10*PER10 + (J15 - J10)*PER15 + (taxable - J15)*PER25;
if (owedTax <= J15)
owedTax = J10* PER10 + (taxable - J10)*PER15;
if (owedTax <= J10)
owedTax = taxable * PER10;
cout << "Your tax is $" << owedTax << "." << endl;
return 0;

if (status == F);
cout << "Please enter your income: "; int income;
cin >> income;
taxable = income - STD_DEDF;
if (taxable > F39)
owedTax = F10*PER10 + (F15-F10)*PER15 + (F28-F25)*PER25+(F33-F28)*PER28 + (F35-F33)*PER33 + (F39-F35)*F35+(taxable-F35)*PER39;
if (owedTax <= F35)
owedTax = F10*PER10 + (F15-F10)*PER15 + (F28-F25)*PER25+(F33 - F28)*PER28 + (F35-F33)*PER33 + (taxable-F33)*PER35;
if (owedTax <= F33)
owedTax = F10*PER10 + (F15-F10)*PER15 + (F28 - F25)*PER25+ (F33 - F28)*PER28+ (taxable - F28)*PER33;
if (owedTax <= F28)
owedTax = F10*PER10 + (F15 - F10)*PER15 + (F28 - F25)*PER25+(taxable - F25)*PER28;
if (owedTax <= F25)
owedTax = F10*PER10 + (F15 - F10)*PER15 + (taxable - F15)*PER25;
if (owedTax <= F15)
owedTax = F10* PER10 + (taxable - F10)*PER15;
if (owedTax <= F10)
owedTax = taxable * PER10;
cout << "Your tax is $" << owedTax << "." << endl;
return 0;

if (status == H);
cout << "Please enter your income: "; int income;
cin >> income;
taxable = income - STD_DEDH;
if (taxable > H39)
owedTax = H10*PER10 + (H15-H10)*PER15 + (H28-H25)*PER25+(H33-H28)*PER28 + (H35-H33)*PER33 + (H39-H35)*H35+(taxable-H35)*PER39;
if (owedTax <= H35)
owedTax = H10*PER10 + (H15-H10)*PER15 + (H28-H25)*PER25+(H33 - H28)*PER28 + (H35-H33)*PER33 + (taxable-H33)*PER35;
if (owedTax <= H33)
owedTax = H10*PER10 + (H15-H10)*PER15 + (H28 - H25)*PER25+ (H33 - H28)*PER28+ (taxable - H28)*PER33;
if (owedTax <= H28)
owedTax = H10*PER10 + (H15 - H10)*PER15 + (H28 - H25)*PER25+(taxable - H25)*PER28;
if (owedTax <= H25)
owedTax = H10*PER10 + (H15 - H10)*PER15 + (taxable - H15)*PER25;
if (owedTax <= H15)
owedTax = H10* PER10 + (taxable - H10)*PER15;
if (owedTax <= H10)
owedTax = taxable * PER10;
cout << "Your tax is $" << owedTax << "." << endl;
return 0;




}




Please edit your post for readability.
https://www.cplusplus.com/articles/jEywvCM9/
 
if (status == S);


and others similar.

These if statements do nothing. The ; at the end terminates the statement.

For if to control one statement then:

1
2
3
4
if (cond)
   // statement if true
else // optional else and statement
   // statement if false 


For if is to control more than one statement then:

1
2
3
4
5
6
7
8
if (cond)
{
    // statements true
} 
else  // optional else and statements
{
    // statements false
}


Last edited on
Hello BB0404,

Did you learn anything from my other post? http://www.cplusplus.com/forum/beginner/273079/#msg1177695

You should first compile your code and fix any errors that you can. When I tried to compile the code I received 310 errors. Turns out that 2 were my fault.

Your {}s do not match up.

You define char S, J, F, H;, but they are uninitialized and only have a garbage value. So, when you get to if (status == S);. This works, but you are comparing "status" to a garbage value. This may never evaluate to true. Then I would refer you to what seeplus has already said.

You either need to reread what you have done so far or look into https://www.learncpp.com/

A good IDE and proper indenting would show some of the problems that you have.

If you continue to not use code tags, see above link, and not post all the code you may have less people wanting to take the time to work on your programs.

Andy
Topic archived. No new replies allowed.