Having problems with the tax tables

I'm having this problem with the calculations of amounts. no matter what amount I input in, it always only calculates the 15%. What am I doing wrong here:

#include <iostream>
using namespace std;

void main()
{

float income, tax, salary = 0;
char status;

cout << "Enter your income: ";
cin>> income;

cout << "Enter your filing status: S = Single or M = Married: ";
cin>> status;

if(income == 0 && income <= 21450 && status == 'S' || 's')
{
tax = income * 15/100;
}
else if(income == 0 && income <= 35800 && status == 'M' || 'm')
{
tax = income * 15/100;
}
else if(income > 21450 && income <= 51900 && status == 'S' || 's')
{
tax = income * 28/100;
}
else if(income > 35800 && income <= 86500 && status == 'M' || 'm')
{
tax = income * 28/100;
}
else if(income > 51900 && status == 'S' || 's')
{
tax = income * 31/100;
}
else if(income > 86500 && status == 'M' || 'm')
{
tax = income * 31/100;
}
salary = income - tax;

cout << "Your salary after taxes is $ " << salary << "." << endl;
Your OR is wrong. It should be status == 'S' || status == 's'.
But beware. OR has a lower precedence than AND, so (income == 0 && income <= 21450 && status == 'S' || status == 's') is the same as ((income == 0 && income <= 21450 && status == 'S') || status == 's'), so you need to add parentheses to change the order of operations: (income == 0 && income <= 21450 && (status == 'S' || status == 's')).

Another solution, probably more practical, would be to change status to lower case and just check with lower case:
status=tolower(status); //You'll have to #include <cctype>
Thanks so much. This solved my problem instantly.
closed account (jLNv0pDG)
income == 0

I believe that should be replaced with:

income >= 0

Otherwise, the program won't work for non-0 amounts less than 21450 or 35000.
Thanks. You were right.
Topic archived. No new replies allowed.