I have to write a code that the user can only enter 's' or 'j'. Anything else will be rejected and send them back to the previous step. If the user enter 's' or 'j', there will be different calculating process for them. This is what I have at the moment, and it doesn't work properly.
How do I fix this? Also, my professor will try to crash the program by entering a negative income, or some random letters beside s, S, j, or J. :)
If I use the while statement, it loops forever. If I use the if statement, it gives me an error and crashes. If I have to terminate the program, what should I do instead?
Oh, and thanks for the correction on my calculation. :)
while (income <= 0)
{
cout << "Invalid input, try again. \n";
cout << Name << ",please enter your taxable income: ";
cin >> income;
}
cout << "What is your filing status? (Enter S for single or J for joint)";
cin >> status;
cin >> status;
while (status != 'j' && status != 's' && status != 'J' && status != 'S')
{
cout << "Invalid input, try again. \n";
cout << Name << ",please enter your filling status: ";
cin >> status;
}
The user must enter an income equal to or greater than 0, and status input could only be s, S, j, J.
The second is looping forever, regardless of what is put in. I am also concerned with the first one because I am not sure if I did it correctly or not.
If I enter s or j, the program works but the calculation is wrong. If I enter any other characters, the program crashes with a message "Tax is undefined."
You not interrupting the program if user will enter something aside from s or j.
Also you have wrong conditions: if (income >= 0 || income <= 1710) it is read as "if income larger than zero or less than one thousand seven hundred ten". Is 1000000 larger than zero? Yes, so this branch will be used instead of correct one. You want to change or statement to and one.
Oh, I get what you are saying now. Now that I am 90% done, I just have little more trouble with the setw part at the end, and writing an ID block. I have to write out what the given constants are and how I did the calculation.
What is the best way to describe the calculation process? Are constants the numbers that he gave me to calculate taxes?