static void ToppingMenu()
{
int toppSelection = 0;
while (toppSelection != 999)
{
Console.Clear();
Console.WriteLine("Create Pizza Menu");
string[] toppName = new string[10] { "Cheese ", "Tomato ", "Mushrooms ", "Green Pepper ", "Black Olives ", "Onions ", "Pepperoni ", "Chicken ", "Tuna ", "End Custom Pizza Creation - Previous Menu" };
int[] toppAmount = new int[9] { 1, 1, 0, 0, 0, 0, 0, 0, 0 };
Console.WriteLine("{0} {1}", toppName[0], toppAmount[0]); //Cheese
Console.WriteLine("{0} {1}", toppName[1], toppAmount[1]); //Tomato
Console.WriteLine("{0} {1}", toppName[2], toppAmount[2]); //Mushrooms
Console.WriteLine("{0} {1}", toppName[3], toppAmount[3]); //Green Pepper
Console.WriteLine("{0} {1}", toppName[4], toppAmount[4]); //Black Olives
Console.WriteLine("{0} {1}", toppName[5], toppAmount[5]); //Onions
Console.WriteLine("{0} {1}", toppName[6], toppAmount[6]); //Pepperonni
Console.WriteLine("{0} {1}", toppName[7], toppAmount[7]); //Chicken
Console.WriteLine("{0} {1}", toppName[8], toppAmount[8]); //Tuna
Console.WriteLine("\n\n\n{0} ", toppName[9]); //Exit to previous menu option
Console.WriteLine("\n\nTo finish order, please enter '999'");
Console.Write("\n\nSelection: ");
toppSelection = int.Parse(Console.ReadLine());
int i = toppSelection - 1; //i is assigned same value as number entered -1,
//i-1 fixes the 1-off fault, where 0 = first topping in array but 1 = first topping by user entry
if (toppAmount[i] > 2) //
{
Console.Write("Error, invalid amount");
}
else if (toppSelection > 0 && toppSelection < 10)
{
toppAmount[i]++;
}
搞到現在我所有的其他方法,這樣做我已經回來了。我期待着我犯了一個令人尷尬的基本錯誤(或者很多!),但是在這裏,對不起,在晚上很抱歉。我的一些編碼看起來可能有點原始,但這是我們今年所教的內容。沒有意義用我還沒有涉及的東西來替換東西,所以如果只是擔心我想增加的值的邏輯/語法=]
toppName =指定澆頭陣列 toppAmount =澆頭值數組,兩個從1開始,因爲他們是默認選擇
toppSelection =用戶輸入並定義了餡料再次選擇
感謝您的幫助球員,抱歉打擾你。
我認爲你需要發佈你的實際代碼,並可能是一個更簡潔的問題。問題似乎是你的'toppAmount [i]'沒有被更新,但它看起來像是這樣,所以這個bug很可能在其他地方。 – 2011-04-05 12:41:58
確定它已被定義。它只是增加1 toppAmount [i] – Erix 2011-04-05 12:47:07
@丹:這是不正確的,看到馬克的答案。 – 2011-04-05 12:49:08