第二行代码是我声明数据类型的地方。在我的第二个if语句中,我尝试使用所有准备就绪的其他变量初始化变量。
int items;
double itemPrice, discountR, totalCost,discountCost, x;
Scanner scan = new Scanner(System.in);
System.out.println("Enter the quantity of the item: -->");
items = scan.nextInt();
System.out.print("Enter the price of an item: -->");
itemPrice = scan.nextDouble();
我做一个扫描仪并声明我的输入。
if(items <= 0 || itemPrice <= 0)
System.out.print("Error: Input must be greater than zero");
else if(items <= 9)
{
totalCost = itemPrice;
discountR = 0;
System.out.print("Your total cost is "+ totalCost);
System.out.print("Your discount rate is "+ discountR);
System.out.print("Discount amount is $O");
System.out.print("The net amount is "+ itemPrice);
}
首先测试一切正常
else if(items >= 10 && items <= 19)
{
discountR = 0.1;
itemPrice * discountR = x; **Where the problem occurs**
System.out.print("Your total cost is "+ totalCost);
System.out.print("Your discount rate is "+ discountR);
System.out.print("Discount amount is $O");
System.out.print("The net amount is "+ itemPrice);
}
答案 0 :(得分:1)
itemPrice * discountR = x; **Where the problem occurs**
将其更改为:
x = itemPrice * discountR;