Some different ways to do it:
Code:
total /= (discountHalfOff == 'y' ? 2 : 1);
Code:
if (discountHalfOff == 'y') {
total /= 2;
}
Code:
if (discountHalfOff == 'y') {
total = total / 2; // Same as: total /= 2
}
We always save the value of half of total in the total variable, but we don't want to use the value of 'discountHalfOff' in the calculation. We just use discountHalfOff to check for the 'y' value, in which case we take half off the value of total.
Originally Posted by
setleaf
If you want to keep the current variables you have then you need to initialize a discountPercentage with ".50". Then read the char into discountHalfOff. As for your if statement it's if discountHalfOff=='Y' then total = itemOnePrice + itemTwoPrice / discountPercentage, and if not then just add up price one and price two.
Are you trying to rip me off?! lol (I think you meant to multiply :P).