I am having issues with my program displaying information from different if statements when they shouldn’t be.
http://i53.tinypic.com/1zyx68.png
#include <iostream>
#include <string>
using namespace std;
int main( )
{
string smreturn = "";
string jointsingle = "";
double income = 0.00;
double taxedincome = 0.00;
{
cout << "\nPlease enter your taxable income: ";
cin >> income;
while (income <= 0)
{
cout << "\n Please enter a valid positive taxable income: ";
cin >> income;
}
cout << "\n";
cout << "\nPlease press m if married and filing for a joint return, or s if filing for a single return: ";
cin >> smreturn;
while (!(smreturn =="m") && !(smreturn =="M") && !(smreturn =="s") && !(smreturn =="S"))
{
cout << "\nPlease press m if married and filing for a joint return,\n or s if filing for a single return: ";
cin >> smreturn;
}
if (smreturn == "m" || "M")
{
if (income >= 0 && income <= 1726)
{
taxedincome = income * .023;
}
if (income >= 1727 && income <= 3450)
{
taxedincome = (income - 1727) * .033 + 40;
}
if (income >= 3451 && income <= 5176)
{
taxedincome = (income - 3450) * .042 + 97;
}
if (income >= 5177 && income <= 6900)
{
taxedincome = (income - 5176) * .052 + 169;
}
if (income > 8626)
{
taxedincome = (income - 8626) * .07 + 362;
}
cout << "\nYour taxable income is:$" << (income);
cout << "\nAnd you are filing a joint return";
cout << "\nYour income tax will be:$" << (taxedincome);
cout << "\n";
}
if (smreturn == "s"||"S")
{
if (income >= 0 && income <= 863)
{
taxedincome = (income * .023);
}
if (income >= 864 && income <= 1726)
{
taxedincome = (income - 863) * .033 + 20;
}
if (income >= 1727 && income <= 2588)
{
taxedincome = (income - 1726) * .042 + 48;
}
if (income >= 2589 && income <= 3450)
{
taxedincome - (income - 2588) * 0.052 + 85;
}
if (income >= 3451 && income <= 4313)
{
taxedincome - (income - 3450) * 0.06 + 129;
}
if (income > 4313)
{
taxedincome - (income - 4313) * 0.07 + 181;
}
cout << "\nYour taxable income is:$" << (income);
cout << "\nAnd you are filing a single return";
cout << "\nYour income tax will be:$" << (taxedincome);
cout << "\n";
}
} cout << "\n";
string returninfo;
if (smreturn == "s" || "S")
{
returninfo == "single return";
}
else
{
returninfo == "joint return";
}
system("PAUSE");
return 0;
}
It is displaying the info from both If statements, saving taxedincome as a single return for a joint return.
should be
And mistakes like these in few other conditions. If you need to compare, you need to repeat it for each identifier in the
ifcondition.