Running Total C#

放肆的年华 提交于 2019-12-02 13:02:30
    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);
    }



    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;
        totalDonationRaised = total;
        totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");
    }
}

I'm trying to use this method for the running total but its adding number when I delete them.

    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");
    }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!