Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在第二次迭代之前无法获得要打印的代码_C# - Fatal编程技术网

C# 在第二次迭代之前无法获得要打印的代码

C# 在第二次迭代之前无法获得要打印的代码,c#,C#,当用户点击“计算”按钮时,无法打印我的代码。只有当他们第二次点击时,打印才会输出。有什么想法吗?我假设if/else语句和print语句的位置存在逻辑错误,但我一直没有弄清楚。我是否应该构造另一个方法来解析输入,然后发送一个值来进行计算 private void calcButton_Click(object sender, EventArgs e) { //declare drink variables double cappuccino = 3.25, es

当用户点击“计算”按钮时,无法打印我的代码。只有当他们第二次点击时,打印才会输出。有什么想法吗?我假设if/else语句和print语句的位置存在逻辑错误,但我一直没有弄清楚。我是否应该构造另一个方法来解析输入,然后发送一个值来进行计算

   private void calcButton_Click(object sender, EventArgs e)
    {
 //declare drink variables

        double cappuccino = 3.25, espresso = 3.5, latte = 3.00, icedLatte = 3.75, icedCappuccino = 3.75;

        //declare coffee bag variables

        double pounder = 9.99, half = 5.99, third = 3.99;

        //other local variables

        double quantity;


        //parse input from user on quantity of goods
        double.TryParse(quantityTextBox.Text, out quantity);

        //series of else if statements used to determine which radio button is keyed by user



        itemAmountLabel.Text = value.ToString("N");
        subTotal += value;

        // surchargeCalc(surcharge);

        //Calculate tax
        tax = taxRate * (subTotal + totalSurcharge);

        total = tax + subTotal + totalSurcharge;

        subtotalLabel.Text = subTotal.ToString("N");
        totalLabel.Text = total.ToString("N");
        taxLabel.Text = tax.ToString("N");


        if (cappuccinoRadioButton.Checked)
        {
            value = quantity * cappuccino;
            return;
        }

        else if (espressoRadioButton.Checked)
        {
            value = quantity * espresso;
            return;
        }
        else if (latteRadioButton.Checked)
        {
            value = quantity * latte;
            return;
        }
        else if (icedLatteRadioButton.Checked)
        {
            value = quantity * icedLatte;
            return;
        }
        else if (icedCappuccinoRadioButton.Checked)
        {
            value = quantity * icedCappuccino;
            return;
        }
        else if (onePoundBagRadioButton.Checked)
        {
            value = quantity * pounder;
            return;
        }
        else if (halfPoungBagRadioButton.Checked)
        {
            value = quantity * half;
            if (surchargeCheckBox.Checked)
            {
                surcharge++;
            }
            return;
        }

        else
        {
            value = quantity * third;
            if (surchargeCheckBox.Checked)
            {
                surcharge++;
            }

        }

您似乎正在将值写在这里:

itemAmountLabel.Text = value.ToString("N");
然后再进行所有计算

一旦完成计算,就应该在方法末尾编写输出

当你移动它时,要注意你的返回语句,好像你在这行之前返回,它仍然不会写


因为所有的返回都在一个大的if-elseif块中,所以您可以删除它们。

Webforms、WPF、winforms?这是什么类型的节目?代码的其余部分在哪里?它不会打印,因为您的代码中没有任何打印语句。
calcButton\u Click
的所有代码都在这里吗?我没有看到结束括号。