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>