根据用户输入更改发票定价

Invoice pricing changes based on user input

这是我的车库计算器发票,用户可以在其中输入 dimension/paint/trim。我的问题出在发票上,我不知道如何根据所选 paint/trim 更改定价。

if (trimPrice == 1 || trimPrice == 2 || trimPrice == 3) {
 if (paintPrice == 1 || paintPrice == 2 || paintPrice == 3) {
  Console.WriteLine("Siding Invoice");
  Console.WriteLine("==================");
  Console.WriteLine(gSide1 + "   Siding Boxes  " + " @" + paintPrice + "=  " + "{0:C}", gTotal1);
  Console.WriteLine(tgTotal2 + "  Trim pieces " + "    @" + trimPrice + "=  " + "{0:C}", tgCost);
  Console.WriteLine("                   Net Total    =  " + ("{0:C}"), nTotal);
  Console.WriteLine("                   GST          =  " + ("{0:C}"), GST);
  Console.WriteLine("                   Delivery Fee =  0.00");
  Console.WriteLine("                   Total        =  " + ("{0:C}"), Total);
  Console.WriteLine("Press Y to Redo");
  Console.Write("Option ");
 }
}

Trim Colour/Price

白色 $28.35

蓝色 $41.65

红色 $49.25

希望我正确理解了你的问题。您需要重新计算您的值。例如,

 if (trimPrice >=1 && trimPrice <= 3 && paintPrice>=1 && paintPrice<=3)
 {

        gTotal1 =  // Your logic here for gTotal1
        tgCost = // Your logic here for tgCost
        nTotal = // Your logic here for nTotal
        GST = // Your logic here for GST
        Total = // Your logic here for Total 
        Console.WriteLine("Siding Invoice");
        Console.WriteLine("==================");
        Console.WriteLine(gSide1 + "   Siding Boxes  " + " @" + paintPrice + "=  " + "{0:C}", gTotal1);
        Console.WriteLine(tgTotal2 + "  Trim pieces " + "    @" + trimPrice + "=  " + "{0:C}", tgCost);
        Console.WriteLine("                   Net Total    =  " + ("{0:C}"), nTotal);
        Console.WriteLine("                   GST          =  " + ("{0:C}"), GST);
        Console.WriteLine("                   Delivery Fee =  0.00");
        Console.WriteLine("                   Total        =  " + ("{0:C}"), Total);
        Console.WriteLine("Press Y to Redo");
        Console.Write("Option ");

    }

您可以保留 Paint 和 Trim 的价格字典。例如,

var dictionaryPaint = new Dictionary<int,int>
            {
                [1] = 100,
                [2] = 200,
                [3] = 300,
            };

我在这里使用数字来绘画,就像在 OP 中一样,但更好的解决方案是使用枚举。声明价格字典后,您可以使用以下内容。

gTotal1 = dictionaryPaint[1] * 12; //12 is just an example. You can use your logic here.

完整代码

var dictionaryPaint = new Dictionary<int,int>
{
    [1] = 100,
    [2] = 200,
    [3] = 300,
};

var dictionaryTrim = new Dictionary<string,int>
{
   [1] = 110,
   [2] = 210,
   [3] = 310,
};
if (trimPrice >=1 && trimPrice <= 3 && paintPrice>=1 && paintPrice<=3)
{

            gTotal1 = dictionaryPaint[1] * 12;  // Your logic here for gTotal1
            tgCost = // Your logic here for tgCost
            nTotal = // Your logic here for nTotal
            GST = // Your logic here for GST
            Total = // Your logic here for Total 
            Console.WriteLine("Siding Invoice");
            Console.WriteLine("==================");
            Console.WriteLine(gSide1 + "   Siding Boxes  " + " @" + paintPrice + "=  " + "{0:C}", gTotal1);
            Console.WriteLine(tgTotal2 + "  Trim pieces " + "    @" + trimPrice + "=  " + "{0:C}", tgCost);
            Console.WriteLine("                   Net Total    =  " + ("{0:C}"), nTotal);
            Console.WriteLine("                   GST          =  " + ("{0:C}"), GST);
            Console.WriteLine("                   Delivery Fee =  0.00");
            Console.WriteLine("                   Total        =  " + ("{0:C}"), Total);
            Console.WriteLine("Press Y to Redo");
            Console.Write("Option ");




}

顺便说一句,请注意你可以替换

if (trimPrice == 1 || trimPrice == 2 || trimPrice == 3) {
 if (paintPrice == 1 || paintPrice == 2 || paintPrice == 3) {

 if (trimPrice >=1 && trimPrice <= 3 && paintPrice>=1 && paintPrice<=3)

假设您的应用程序 运行 期间价格没有变化,您可以创建一个静态 Dictionary 来根据 trim 类型或油漆类型标识符存储价格。

static readonly Dictionary<int, int> TrimPrices = new Dictionary<int, int>
{
    { 1, 100 },
    { 2, 200 },
    { 3, 500 }
};

然后您可以访问并打印所选 trim 的价格,如下所示:

Console.WriteLine(TrimPrices[trimPrice]);