我正在创建一个捐赠应用程序,该应用程序将读取文本框中的输入,并将其转换为double。然后使用方法operatingCost
,它应该将转换后的double值除以17%(营业费)。当前在该方法中,我进入了变量dontationBFees
,然后将其除以17,然后创建一个新变量afterFees
。一切正常,但我需要创建一个运行总计,以保存所有捐款。它应显示该日期之前所有捐赠的慈善筹款总额(即捐赠的总额减去所有运营成本)。我知道我需要一个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)
{
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);
}
}
}
答案 0 :(得分:0)
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");
}
}
答案 1 :(得分:0)
我正在尝试将此方法用于运行总计,但是在删除它们时会增加它的数量。
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");
}
}