問題描述
我正在創建一個捐贈應用程序,它讀取文本框中的輸入,將其轉換為雙精度.然后使用 operatingCost
方法,它應該將轉換后的兩倍除以 17%(營業費用).目前在該方法中,我有變量 dontationBFees
進入,然后除以 17 并創建一個新變量 afterFees
.一切正常,但我需要創建一個運行總計來保存所有捐款.它應該顯示截至該點的所有捐贈為慈善機構籌集的總金額(即捐贈的總金額減去所有運營成本).我知道我需要一個 while 循環或執行 while 循環,以便應用程序運行并不斷添加數據.我只是不明白為什么這段代碼沒有產生運行總數.我正在尋求幫助.有什么我忽略的.
I'm creating a donation application that reads the input in a textbox, converts it to a double. Then using the method operatingCost
, it should take that converted double and divide it by 17% (operating fees). Currently in the method, I have the variable dontationBFees
coming in and then being divided by 17 and creating a new variable afterFees
. Everything is working fine but I need to create a running total that will save all of the donations. It should display the total amount raised for the charity (that is, the total amount donated less all operating costs) for all donations up to that point. I know I need a while loop or do while loop so that the app runs and keeps adding the data. I just don't see why this code isn't producing the running total. I'm looking for help. Is there something I'm overlooking.
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);
}
}
}
推薦答案
我正在嘗試使用這種方法來計算運行總數,但是當我刪除它們時它會增加數字.
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");
}
}
這篇關于運行總 C#的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!