如何乘以增值税

本文关键字:增值税 何乘 | 更新日期: 2023-09-27 17:59:18

我需要接受在CollectHeader()中输入的增值税

计算并生成一个名为totalPrice的输出,以显示productPrice*salesTax

我已经尝试了多种方法,我是不成功的

这是我的

namespace ConsoleApplication1
{
class CustomerOrder
{
    string company;
    string productName1;
    int productAmount1;
    decimal productPrice1;
    string productName2;
    int productAmount2;
    decimal productPrice2;
    string productName3;
    int productAmount3;
    decimal productPrice3;
    string companyName;
    string companyAddress;
    int salesTax;
    public string ProductName1
    {
        get
        {
            return productName1;
        }
        set
        {
            productName1 = value;
        }
    }
    public string ProductName2
    {
        get
        {
            return productName2;
        }
        set
        {
            productName2 = value;
        }
    }
    public string ProductName3
    {
        get
        {
            return productName3;
        }
        set
        {
            productName3 = value;
        }
    }
    public int ProductAmount1
    {
        get
        {
            return productAmount1;
        }
        set
        {
            productAmount1 = value;
        }
    }
    public int ProductAmount2
    {
        get
        {
            return productAmount2;
        }
        set
        {
            productAmount2 = value;
        }
    }
    public int ProductAmount3
    {
        get
        {
            return productAmount3;
        }
        set
        {
            productAmount3 = value;
        }
    }
    public decimal ProductPrice1
    {
        get
        {
            return productPrice1;
        }
        set
        {
            productPrice1 = value;
        }
    }
    public decimal ProductPrice2
    {
        get
        {
            return productPrice2;
        }
        set
        {
            productPrice2 = value;
        }
    }
    public decimal ProductPrice3
    {
        get
        {
            return productPrice3;
        }
        set
        {
            productPrice3 = value;
        }
    }
    public string CompanyName
    {
        get
        {
            return companyName;
        }
        set
        {
            companyName = value;
        }
    }
    public string CompanyAddress
    {
        get
        {
            return companyAddress;
        }
        set
        {
            companyAddress = value;
        }
    }
    public int SalesTax
    {
        get
        {
            return salesTax;
        }
        set
        {
            salesTax = value;
        }
    }

    public CustomerOrder()
    {             
       }
    public void CollectHeader()
    {
        string inputValue;
        Console.WriteLine("What name of the company {0}?", companyName);
        inputValue = Console.ReadLine();
        companyName = inputValue;
        Console.WriteLine("What is the address?", companyAddress);
        inputValue = Console.ReadLine();
        companyAddress = inputValue;
        Console.WriteLine("What is the sales tax?", salesTax);
        inputValue = Console.ReadLine();
        salesTax = Int32.Parse(inputValue);
    }

    public void PrintHeader()
    {
        Console.WriteLine("This is the {0} Customer Order Storage program.", companyName);
        Console.WriteLine("Address: {0}", companyAddress);
        Console.WriteLine("Sales Tax: {0}", salesTax);
    }
    public static void PrintEntryHeader()
    {
        Console.WriteLine("Please enter the following details about the order.'n");
    }
    public static void PrintSummaryHeader()
    {
        Console.WriteLine("Order entry is now complete.'nThe following orders have been stored");
    }
    public void PrintSummary()
    {
        Console.WriteLine(this.ToString());
        Console.ReadKey();
    }
    public void CollectAllInput_Counter()
    {
        int productNumber = 1;
        while (productNumber <= 3)
        {
            CollectItemSwitch(productNumber);
            productNumber++;
        }
    }
    public void CollectAllInput_For()
    {
        for (int productNumber = 1; productNumber <= 3; productNumber++)
        {
            CollectItemSwitch(productNumber);
        }
    }
    public void CollectItem(int productNumber)
    {
        string productName;
        int productAmount;
        decimal productPrice;
        string inputValue;
        Console.WriteLine("What name of the product ordered {0}?", productNumber);
        inputValue = Console.ReadLine();
        productName = inputValue;
        Console.WriteLine("What is the inventory quantity of drink {0}?", productNumber);
        inputValue = Console.ReadLine();
        productAmount = Int32.Parse(inputValue);
        Console.WriteLine("What is the price of the product named {0}?", productNumber);
        inputValue = Console.ReadLine();
        productPrice = Decimal.Parse(inputValue);
        if (productNumber > 0 && productNumber < 4)
        {
            if (productNumber == 1)
            {
                this.productName1 = productName;
                this.productAmount1 = productAmount;
                this.productPrice1 = productPrice;
            }
            if (productNumber == 2)
            {
                this.productName2 = productName;
                this.productAmount2 = productAmount;
                this.productPrice2 = productPrice;
            }
            if (productNumber == 3)
            {
                this.productName3 = productName;
                this.productAmount3 = productAmount;
                this.productPrice3 = productPrice;
            }
        }
    }

    public void CollectItemSwitch(int productNumber)
    {
        if (productNumber > 0 && productNumber < 4)
        {
            string productName;
            int productAmount;
            decimal productPrice;
            string inputValue;
            Console.WriteLine("What is the name of the product {0}'n", productNumber);
            inputValue = Console.ReadLine();
            productName = inputValue;
            Console.WriteLine("What is the amount of product {0}'n", productNumber);
            inputValue = Console.ReadLine();
            productAmount = Int32.Parse(inputValue);
            if (Int32.TryParse(inputValue, out productAmount) == false)
            {
                Console.WriteLine("[{0}] is not a valid number. Quantity is set to 0.", inputValue);
                productAmount = 0;
            }
            Console.WriteLine("What is the price of product {0}", productNumber);
            inputValue = Console.ReadLine();
            productPrice = Decimal.Parse(inputValue);
            if (!Decimal.TryParse(inputValue, out productPrice) == false)
            {
                Console.WriteLine("[{0}] is not a valid price. Price is set to 0.00.", inputValue);
                }
            switch (productNumber)
            {
                case 1:
                    this.productName1 = productName;
                    this.productAmount1 = productAmount;
                    this.productPrice1 = productPrice;
                    break;
                case 2:
                    this.productName2 = productName;
                    this.productAmount2 = productAmount;
                    this.productPrice2 = productPrice;
                    break;
                case 3:
                    this.productName3 = productName;
                    this.productAmount3 = productAmount;
                    this.productPrice3 = productPrice;
                    break;
            }
        }
        else
        {
            throw new Exception(String.Format("The order number [{0}] is not valid", productNumber));
        }
    }



    public override string ToString()
    {
        string outputString = company + "'n";
        outputString += "Product 1: " + productName1 + ", Amount: " + productAmount1 + ", Price" + productPrice1 + "'n";
        outputString += "Product 2: " + productName2 + ", Amount: " + productAmount2 + ", Price" + productPrice2 + "'n";
        outputString += "Product 3: " + productName3 + ", Amount: " + productAmount3 + ", Price" + productPrice3;
        return outputString;
    }
}
}

如何乘以增值税

public void CollectHeader()
{
    string inputValue;
    Console.WriteLine("What name of the company {0}?", companyName);
    inputValue = Console.ReadLine();
    companyName = inputValue;
    Console.WriteLine("What is the address?", companyAddress);
    inputValue = Console.ReadLine();
    companyAddress = inputValue;
    Console.WriteLine("What is the sales tax?", salesTax);
    inputValue = Console.ReadLine();
    float salesTax = float.Parse(inputValue);
    //Assuming that salesTax is in the form of 1 + decimal percentage. For example, for a 5% tax, salesTax would be 1.05.
    float totalPrice = productPrice1*salesTax + productPrice2*salesTax + productPrice3*salesTax;
    Console.WriteLine("The total cost is " + totalPrice.ToString("c2") + ". Thank you for shopping at StackOverFlowmart.");
}