Inequality in if/else statement

I am working on an assignment and I need to make different if/else statements to calculate penalties on a bill. Anyway, if the person pays between 20%-50% of their billing amount, then they receive a 10% penalty on their remaining balance. I am having trouble figuring out how to set up this statement.


1
2
else if(desiredPay >= billingAmount * .20 || desiredPay <= billingAmount * .50)
        cout << "Your remaining balance is $" << remainingBalance << " with a penalty of $" << remainingBalance * ATLEAST_20 << "." << endl;


The ATLEAST_20 is a constant that applies a 10% penalty on the remaining balance.

I am not sure how to set up an inequality such as 20% <= x <= 50%
Last edited on
You do currently write: "if X is either more than Y or less than Z".

Lets take W that is larger than Z. The latter condition would be false, but since W is larger than Y, the whole is true.

Only if Z would be less than Y, there would be values Z < h < Y, where your condition would be false. Now it is never.

What you want is that both conditions must be true.
X must be larger than Y and X must be less than Z.
Can you explain how I would format that in the if statement?
bottom <= pay && pay <= top
you know and is a valid operator
you may write bottom <= pay and pay <= top

¿but is it really the confusion about || meaning what causes this kind of errors?
Topic archived. No new replies allowed.