我在制作计算器时遇到了一些麻烦。我似乎无法输入项目名称,只能输入数字。此外,它只需要最后的价格和数量,并将它们相乘而不是整体。更新:我所做的更改至小计和休息的代码,但它不断告诉我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