Mar 1, 2013 at 10:13pm
how do i fix my code?
now i am trying to add a while loop so the program will only exit if you put 0 or a lower number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main()
{
// declare variables
int salary; // income
string Marital_status; //Marital Status
string taxFee;
double taxPercent;
double tax;
// get input from user
while (salary <= 0; salary++)
{
cout << "please enter a valid salary ";
cin >> salary;
}
cout << "what is your income?"<<endl;
cin >> salary;
cout << "are you married or single?"<<endl;
cin >> Marital_status;
// processing
if (Marital_status == "s" || Marital_status == "S") //Single
{
if ((salary >= 0) && (salary < 25000))
{
taxFee = "single first class tax";
taxPercent = .10;
}
else if ((salary >= 25000) && (salary < 75000))
{
taxFee = "single second class tax";
taxPercent = .20;
}
else if ((salary >= 75000) && (salary < 125000))
{
taxFee = "single third class tax";
taxPercent = .30;
}
else if (salary <= 125,000)
{
taxFee = "single fourth class tax";
taxPercent = .40;
}
}
if (Marital_status == "m" || Marital_status == "M") //Married
{
if ((salary >= 0) && (salary < 25000))
{
taxFee = "married first class tax";
taxPercent = .08;
}
else if ((salary >= 25000) && (salary < 75000))
{
taxFee = "married second class tax";
taxPercent = .15;
}
else if ((salary >= 75000) && (salary < 125000))
{
taxFee = "married third class tax";
taxPercent = .25;
}
else if (salary <= 125,000)
{
taxFee = "married fourth class tax";
taxPercent = .30;
}
}
// do processing
tax = salary * taxPercent;
// output results
cout << "based on the salary" << taxFee << " for $" << taxPercent << endl;
cout << "your total tax is $" << tax << " per month" << endl;
system("PAUSE");
return 0;
}
|
Last edited on Mar 1, 2013 at 11:42pm
Mar 1, 2013 at 10:19pm
You should write
if (Marital_status == "m" || Marital_status == "M")
Your variant of code try to convert address of "M" to bool (and this is always true).
Edit: same should be done with "S"
.
Last edited on Mar 1, 2013 at 10:20pm
Mar 1, 2013 at 10:36pm
i still have the same problem.
Mar 1, 2013 at 10:44pm
If an user types "m" the application reports single" and vice versa.
Maybe this is your error?
Or maybe I don't understand your question. Can you show your input and desired output?
Mar 1, 2013 at 10:46pm
It looks like you have the program to send out data for single tax if they select married and vice versa.
Mar 2, 2013 at 12:07am
now i am trying to add a while loop so the program will only exit if you put 0 or a lower number.
Mar 2, 2013 at 12:26am
while(num > 0)
{
...
...
}