的代码,其中(cancel1 = 2)的布尔“取消”的部分是不读:变量不是读
while (done !=0){
pizzaChoice = readInt ("Choose the type of pizza you wish to order");
double quantity = readInt ("How many " + type[pizzaChoice] + " pizzas do you wish to buy (Maximum pizzas per order is 5)");
if(quantity >= max){
System.out.println("Sorry you cannot order more than five pizzas");
if ((quantity - max) <= 0){
double pizzasLeft = max - quantity;
System.out.println("You can still order " + pizzasLeft + " pizzas");
pizzasLeft2 = pizzasLeft2 - pizzasLeft;
该下一如果环是问题所在
if (pizzasLeft2 <= 0){
boolean cancel = true;
int cancel1 = readInt("Press 2 to cancel your order and start again");
if(cancel1 == 2){
cancel = false;
}
}
}
}
done= readInt ("Press 0 if you are done or press 1 to make another pizza order");
double total1 = quantity*price[pizzaChoice];
total2 = total2 + total1;
}
名为'cancel'的'boolean'只被赋值,它永远不会被读取。它的目的是什么?你在别处是否有另一个名为'cancel'的布尔值,并且意外地重新声明它,隐藏另一个? – hmjd
'双'是比萨饼数量真正奇怪的选择。您的客户可以订购1.2匹比萨饼吗? – Mat
为什么是布尔取消?什么是pizzasLeft2 ?,它是输入第一个if ?,顺便说一下,你声明取消,'if' – Kris