的代碼,其中(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