0
hye i want to know how to do the coding when the question give the no of items bought and the price. for example number of items bought 1-9 and the discount price for 0.01-10.00 is 0%, 10.01-100.00 is 2% and for 100.01 is 5%.
2 ответов
0
use if-else control staments :
int totalPrice = 100, discount;
if(totalPrice <= 0)
{ discount = 0; }
else if(totalPrice <= 100)
{ discount = 0.02; }
else if(totalPrice == 100.01)
{ discount = 0.05; }
0
int numOfItems = 5;
int price = 50;
if(numOfItems > 0 && numOfItems < 10) {
if(price > 10 && price <= 100) {
price *= 0.98
} else if(price > 100) {
price *= 0.95
}
}
System.out.println(price); //49