1

我有这个 Windows 应用程序咖啡馆,它允许用户进行选择,然后它显示所选项目的成本、小计、税款、总计、当天的交易数量,我需要它来显示收取的总销售税为好。我认为计算这与我计算交易数量的方式相似,但我还没有弄清楚。有任何想法吗?

public partial class Form1 : Form
{
    int clicks = 0;
    double totalSalesTaxCollected = 0;

    public Form1()
    {
        InitializeComponent();
        InitializeControls();

    }
    private void button1_Click(object sender, EventArgs e)
    {

        clicks++;
        displayBill();

    }

    private void displayBill()
    {

      // int[] listArray = listBox1.getSelectedIndices();
      // SelectedIndexCollection listArray = listBox1.SelectedIndices;
        double localTax = 0.01;
        double stateTax = 0.06;
        double tax;
        double subTotal = 0;
        double total;

        //Set the text area to non-edit mode and start
        //with an empty string.
        textBox1.ReadOnly = true;
        textBox1.Text = "";
        textBox1.AppendText("           C# KIOSK A LA CARTE\n\n");
        textBox1.AppendText("--------------- Welcome ----------------\n\n");


        //Calculate the cost of the items ordered.
        for (int index = 0; index < listBox1.SelectedIndices.Count; index++)
        {
            subTotal = subTotal + yourChoicesPrices[listBox1.SelectedIndices[index]];

        }

              tax = (localTax + stateTax) * subTotal;
              total = subTotal + tax;

                  //Display the costs.
              for (int index = 0; index < listBox1.SelectedIndices.Count; index++)
              {
                 textBox1.AppendText(yourChoicesItems[listBox1.SelectedIndices[index]] +"\n");
              }

            textBox1.AppendText("\n");
            textBox1.AppendText("SUB TOTAL\t\t" + String.Format("{0:C}", subTotal) + "\n");
            textBox1.AppendText("TAX           \t\t"+ String.Format("{0:C}" , tax) + "\n");
            textBox1.AppendText("TOTAL     \t\t"+ String.Format("{0:C}" , total) + "\n\n");
            textBox1.AppendText("\n");
            textBox1.AppendText("Thank you - Have a Nice Day\n\n");
            textBox1.AppendText("\n");
            textBox1.AppendText("Total sales: \t\t" + clicks + "\n" );
            textBox1.AppendText("Total sales tax collected: \t\t" + totalSalesTaxCollected);

                  //Reset list array.
            listBox1.ClearSelected();
    }
4

2 回答 2

1

除非我错过了,否则我认为您需要..并且我在这行之后猜测:

tax = (localTax + stateTax) * subTotal;
total = subTotal + tax;

添加:

 totalSalesTaxCollected+=total;
于 2012-10-24T17:06:42.943 回答
1

tax = (localTax + stateTax) * subTotal; total = subTotal + tax;

添加totalSalesTaxCollected += tax;

于 2012-10-24T17:08:18.707 回答