运行总C#

运行总C#,c#,onclick,cumulative-sum,C#,Onclick,Cumulative Sum,我正在创建一个捐赠应用程序,它读取文本框中的输入,并将其转换为双精度。然后使用运营成本的方法,应将转换后的成本除以17%(运营费)。目前在该方法中,变量dontationBFees进入,然后除以17,创建一个新变量afterFees。一切都很好,但我需要创建一个运行总数,将保存所有的捐款。它应该显示为慈善机构筹集的总金额(即捐赠总额减去所有运营成本)截至该日期的所有捐赠。我知道我需要一个while循环或do while循环,以便应用程序运行并不断添加数据。我只是不明白为什么这段代码不能生成运行总

我正在创建一个捐赠应用程序,它读取文本框中的输入,并将其转换为双精度。然后使用
运营成本
的方法,应将转换后的成本除以17%(运营费)。目前在该方法中,变量
dontationBFees
进入,然后除以17,创建一个新变量
afterFees
。一切都很好,但我需要创建一个运行总数,将保存所有的捐款。它应该显示为慈善机构筹集的总金额(即捐赠总额减去所有运营成本)截至该日期的所有捐赠。我知道我需要一个while循环或do while循环,以便应用程序运行并不断添加数据。我只是不明白为什么这段代码不能生成运行总数。我在寻求帮助。有什么我忽略了的吗

   private decimal donationBFees = 0;

    void deductOperatingCost(ref decimal afterFeesParam)
    {
        afterFeesParam = afterFeesParam - (afterFeesParam  / 100 * 17);
    }


    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Boolean set = true;
        do
        {

            String donationBeforeFees;
            decimal totalDonationRaised;

            donationBeforeFees = donationBox.Text;
            donationBFees = System.Convert.ToDecimal(donationBeforeFees);


            decimal afterFees = donationBFees;
            deductOperatingCost(ref afterFees);
            afterFeesBox.Text = afterFees.ToString("$###, ##0.00");

            //This is the for loop I'm using to get the running total
            for (int i = 0; i < afterFees; i++)
            {
                decimal total = 0;
                total += afterFees;
                totalDonationRaised = total;
                totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");
            }

        } while (set == false);
    }

}
private decimal donationBFees=0;
无效扣除运营成本(参考小数点后的费用)
{
afterFeesParam=afterFeesParam-(afterFeesParam/100*17);
}
私有无效按钮\u单击(对象发送者,路由目标e)
{
布尔集合=真;
做
{
收费前的字符串捐赠;
十进制总数;
donationBeforeFees=donationBox.Text;
donationBFees=System.Convert.ToDecimal(donationBeforeFees);
小数后费用=捐赠基金;
扣除运营成本(参考附加费);
afterFeesBox.Text=afterFees.ToString($##########0.00”);
//这是我用来获取运行总数的for循环
对于(int i=0;i

}

我尝试对运行总数使用此方法,但在删除它们时,它会增加数字

    private decimal donationBFees = 0;
    private decimal total = 0;
    private decimal afterFees = 0;
    private decimal totalDonationRaised;

    void deductOperatingCost(ref decimal afterFeesParam)
    {
        afterFeesParam = afterFeesParam - (afterFeesParam  / 100 * 17);
    }

    void runningTotal(ref decimal runningTotalParam)
    {
        runningTotalParam = runningTotalParam + runningTotalParam;
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {


            String donationBeforeFees;


            donationBeforeFees = donationBox.Text;
            donationBFees = System.Convert.ToDecimal(donationBeforeFees);


            decimal afterFees = donationBFees;
            deductOperatingCost(ref afterFees);
            afterFeesBox.Text = afterFees.ToString("$###, ##0.00");

            total = afterFees;
            totalDonationRaised = total;
            totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");

    }

    private void donationBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        //total += afterFees;

        runningTotal(ref total);
        totalDonationRaised = total;
        totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");
    }

}

如果你除以17,那不是17%是的,我知道这就是为什么代码中的捐款*100/17。这会给你一个真正的数字乘以倍数,然后除以得到百分比。你(试图)在一个按钮点击中循环,这不会让用户界面屈服。您还可以在内部
for
循环中每次重新初始化
total
。为什么有实际上不循环的
do
循环?将
decimal total=0
移动到
for
循环之外,并摆脱
do…while
循环。似乎for循环正在锁定系统,因为当我在代码中包含它时,其他部分甚至不工作。好的,我现在使用TextChanged事件来处理部分正在运行的总计。现在,它显示总数,但在每个条目未添加到总数后,它会发生变化。有什么想法吗?好的,我现在使用TextChanged事件来处理运行总数的一部分。现在,它显示总数,但在每个条目未添加到总数后,它会发生变化。有什么想法吗?
    private decimal donationBFees = 0;
    private decimal total = 0;
    private decimal afterFees = 0;
    private decimal totalDonationRaised;

    void deductOperatingCost(ref decimal afterFeesParam)
    {
        afterFeesParam = afterFeesParam - (afterFeesParam  / 100 * 17);
    }

    void runningTotal(ref decimal runningTotalParam)
    {
        runningTotalParam = runningTotalParam + runningTotalParam;
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {


            String donationBeforeFees;


            donationBeforeFees = donationBox.Text;
            donationBFees = System.Convert.ToDecimal(donationBeforeFees);


            decimal afterFees = donationBFees;
            deductOperatingCost(ref afterFees);
            afterFeesBox.Text = afterFees.ToString("$###, ##0.00");

            total = afterFees;
            totalDonationRaised = total;
            totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");

    }

    private void donationBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        //total += afterFees;

        runningTotal(ref total);
        totalDonationRaised = total;
        totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");
    }

}