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