对于此代码,我希望它显示“您的折扣为 $ 。”您的总金额为 $ 。”但当sales >= 10
它小于 10 时,我希望它显示 **“无折扣。你的总数是$。”
问题是无论我输入什么数字,它都会说“没有折扣。你的总美元。” 它进行计算。anyhelp 将不胜感激。
import java.util.Scanner;
public class SoftwareSales
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int sales = 99;
int quantity;
double total;
double rate = 0;
double discount;
System.out.print ("Enter amount of packages purchased: ");
quantity = keyboard.nextInt();
total = quantity * sales;
discount = total * rate;
total = total - discount;
if (sales < 10) {
if (sales >= 10 || sales <= 19)
rate = 0.20;
else if (sales >= 20 || sales <=49)
rate = 0.30;
else if (sales >= 50 || sales <=99)
rate = 0.40;
else if (sales > 100)
rate = 0.50;
System.out.println("Your discount is $" + (int)discount +
". Your total is: $" + (int)total);
} else {
System.out.print("No discount. " +
"Your total is: $" + (int)total);
}
}
}