我在製作計算器時遇到了一些麻煩。我似乎無法輸入項目名稱,只能輸入數字。此外,它只需要最後的價格和數量,並將它們相乘而不是整體。更新:我所做的更改至小計和休息的代碼,但它不斷告訴我C中的二維數組計算器#
錯誤CS0029
無法隱式轉換類型「字符串」到「字符串[,]」錯誤CS0019
操作「==」不能應用於operandstype'string [,]」和‘廉政’
我似乎無法使它工作或最後添加一個列表。任何幫助,將不勝感激。
int[] array;
string[,] name = new string[100, 4];
decimal counter;
decimal price;
decimal subtotal;
decimal tax;
decimal total;
decimal quantity;
subtotal = 0;
counter = 0;
array = new int[5];
while (counter <= 10)
{
Console.Write("Item{0}", counter + 1);
Console.Write(" Enter item name: ");
name = Console.ReadLine();
if (name == 0)
break;
Console.Write(" Enter price: ");
price = Convert.ToDecimal(Console.ReadLine());
counter = counter + 1;
Console.Write(" Enter quantity: ");
quantity= Convert.ToInt32(Console.ReadLine());
subtotal += price * quantity;
}
Console.WriteLine("-------------------");
Console.WriteLine("\nNumber of Items:{0}", counter);
Console.WriteLine("Subtotal is {0}", subtotal);
tax = subtotal * 0.065M;
Console.WriteLine("Tax is {0}", tax);
total = tax + subtotal;
Console.WriteLine("Total is {0}", total);
Console.WriteLine("Thanks for shopping! Please come again.");
Console.Read();
我也知道,我需要在代碼for (int counter = 0; counter < array.Length; counter++)
太多,但它不會工作。感謝您的提前幫助和幫助。
您的名稱變量是一個int,並且您將控制檯輸入轉換爲整數,所以這就是爲什麼只能將數字放入名稱中的原因。您還在循環中設置小計=「X」,因此它將始終設置爲最後一次計算。您應該使用+ =作爲運行小計。 – Aaron
使用'array'在哪裏? – ja72
我試圖在while循環之前使用它,但我確信我做錯了。 – Shade