And your code you input in your last response, is that not what my code is doing? |
That is your code - - I was just saying that I don't think it's doing what you intend it to do. I think what you mean to do is calculate the pension contribution dollar amount and subtract that from the gross pay, so they aren't taxed on the amount they set aside in the pension plan. What the code is doing is subtracting the percent amount, in this case .05, from the gross amount. I think you mean to subtract the 2500?
1 2 3 4
|
cin >> percent; // percent = 5
percent = percent / 100; // percent = .05
grossPay = gross * percent; // grossPay = 50000 * .05 = 2500
gross = gross - percent; // gross = 50000 - .05
|
while ((status != 'M') || (status != 'S'))
This is testing whether one of the conditions there is true. If they enter 'S' - the first condition, status !=M, is true. If they enter 'M', the second condition, status!='S', is true. If they put in 'H', both conditions are true. Whether they put in a valid option or invalid option, that logic is going to be true and they won't get out of the while loop.
while (!(status == 'M' || status == 'S'))
This is saying while the status is not equal to either 'M' or 'S', continue the loop.
Or, you can distribute the negative across the two conditions, but then you need to flip the logical OR (||) to a logical AND (&&) like this.
while ((status != 'M') && (status != 'S'))
DeMorgan's laws can be helpful in figuring this out. :)
http://en.wikipedia.org/wiki/De_Morgan's_laws