C# 在BTN上运行总C
一切都很好,但我需要创建一个运行总数,将保存所有的捐款。它应该显示为慈善机构筹集的总金额,也就是说,捐赠的总金额减去到那时为止所有捐赠的所有运营成本。我知道我需要一个while循环或do while循环,以便应用程序运行并不断添加数据。我只是不明白为什么这段代码不能生成运行总数。我在寻求帮助。有什么我忽略了的吗C# 在BTN上运行总C,c#,for-loop,C#,For Loop,一切都很好,但我需要创建一个运行总数,将保存所有的捐款。它应该显示为慈善机构筹集的总金额,也就是说,捐赠的总金额减去到那时为止所有捐赠的所有运营成本。我知道我需要一个while循环或do while循环,以便应用程序运行并不断添加数据。我只是不明白为什么这段代码不能生成运行总数。我在寻求帮助。有什么我忽略了的吗 private decimal donationBFees = 0; void deductOperatingCost(ref decimal afterFeesParam) {
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");
}
}
下面的代码是否正确运行
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");
}
总计在按钮单击方法中声明。一旦该方法存在,Total的值就会丢失。如果您希望total在多次调用Button_Click时保持其值,那么该变量需要存在于该方法的范围之外。您不能在之后迭代十进制值。。。你需要一个数组或者一个集合,你应该拥有它,而不是发布本质上相同的东西。我只是觉得里面的信息太多了description@Fabjan这是因为变量total被覆盖了吗?似乎for循环正在锁定系统,因为当我在代码中包含它时,其他部分甚至都不工作。代码底部的for循环会这样做似乎很奇怪。有什么想法吗?嘿,马特,这没用。关于这一点,十进位税后费用=扣除运营成本税前捐款;你加上扣除运营成本了吗?错误是什么?