我有这段代码,可以为一定数量的物品输入一个数字。每件商品的底价为 6.00 美元,然后根据商品数量对其应用折扣,1-4 件商品无折扣,5-9 件商品有 10% 折扣,10-14 件商品有 14% 折扣, 15 人或以上可享受 20% 的折扣。我运行了这个程序,但它似乎输出的是最终价格,没有从总价中扣除折扣。我究竟做错了什么?
static void Main(string[] args)
{
int quantity;
double price;
quantity = GetQuantity();
price = CalculatePrice(quantity);
WriteLine("Final price for {0} items is {1}.",
quantity, price.ToString("c"));
}
private static int GetQuantity()
{
int quantity;
Write("Enter number of items >> ");
quantity = Convert.ToInt32(ReadLine());
return quantity;
}
private static double CalculatePrice(int quantityOrdered)
{
double PRICE_PER_ITEM = 6.00;
double price = 0;
double discount = 0;
int[] quanLimits = { 0, 5, 10, 15 };
double[] limits = { 0, 0.10, 0.14, 0.20 };
for (int x = limits.Length - 1; x >= 0; x--)
if (quantityOrdered >= quanLimits[x])
discount = limits[x];
//int x = 0;
price = quantityOrdered * PRICE_PER_ITEM;
price = price - (price * discount);
return price;
}
蓝山帝景
相关分类