一切正常,但我需要创建一个运行总计,以保存所有捐款。它应显示该日期之前所有捐赠的慈善筹款总额(即捐赠的总额减去所有运营成本)。我知道我需要一个while循环或执行while while循环,以便应用程序运行并不断添加数据。我只是不明白为什么这段代码没有产生运行总数。我正在寻求帮助。有什么我要忽略的吗?
private decimal donationBFees = 0;
void deductOperatingCost(ref decimal afterFeesParam)
{
afterFeesParam = afterFeesParam - (afterFeesParam / 100 * 17);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
String donationBeforeFees;
decimal totalDonationRaised;
donationBeforeFees = donationBox.Text;
donationBFees = System.Convert.ToDecimal(donationBeforeFees);
decimal afterFees = donationBFees;
deductOperatingCost(ref afterFees);
afterFeesBox.Text = afterFees.ToString("$###, ##0.00");
decimal total = 0;
//This is the for loop I'm using to get the running total
for (int i = 0; i < afterFees; i++)
{
total += afterFees;
totalDonationRaised = total;
totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");
}
}
答案 0 :(得分:0)
下面的代码是否正确运行?
private decimal donationBFees = 0;
decimal deductOperatingCost(decimal afterFeesParam)
{
return afterFeesParam - (afterFeesParam / 100 * 17);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
decimal donationBeforeFees = System.Convert.ToDecimal(donationBox.Text);
decimal afterFees = deductOperatingCost(donationBeforeFees);
afterFeesBox.Text = afterFees.ToString("$###, ##0.00");
decimal totalDonationRaised = System.Convert.ToDecimal(totalDonationsBox.Text) + afterFees;
totalDonationsBox.Text = totalDonationRaised.ToString("$###, ##0.00");
}