[英]Adding User Defined data
首先我想說的是這是我的作業。 我不是在尋找答案來幫助弄清楚我做錯了什么。 這是我的第一個編程課程,到目前為止我一直都很棒。 現在突然間我迷路了。
問題:創建一個應用程序,讓用戶輸入運營其汽車所產生的以下費用的月度成本:貸款支付,保險,汽油,機油,輪胎和維護。 然后,該計划應顯示這些費用的每月總費用以及這些費用的年度總費用。
這就是我建立的:
private void totalMonthlyButton_Click(object sender,EventArgs e){
decimal loan; // Monthly cost of loan
decimal insurance; // Monthly insurance cost
decimal gas; // Monthly gas cost
decimal oil; // Monthly oil cost
decimal tires; // Monthly tire cost
decimal maintenance; // Monthly maintenance cost
decimal monthlyCost; // Monthly total cost
// Get the loan amount.
loan = decimal.Parse(loanTextBox.Text);
// Get the insurance amount.
insurance = decimal.Parse(insTextBox.Text);
// Get the gas amount.
gas = decimal.Parse(gasTextBox.Text);
// Get the oil amount.
oil = decimal.Parse(oilTextBox.Text);
// get the tires amount.
tires = decimal.Parse(tiresTextBox.Text);
// Get the maintenance amount.
maintenance = decimal.Parse(mainTextBox.Text);
// determine the monthly cost.
monthlyCost = decimal.Parse(totalMonthlyLabel.Text);
// Calculate monthly cost.
monthlyCost = loan + insurance + gas + oil + tires + maintenance;
// Display the monthlyCost in the correct control.
非常感謝任何幫助。 如果我正朝着正確的方向前進,如果我完全關閉,下一步去哪里,我再也不想要答案。
謝謝大家。
這是我現在能想到的最佳方式:
decimal loan; // Monthly cost of loan
decimal insurance; // Monthly insurance cost
decimal gas; // Monthly gas cost
decimal oil; // Monthly oil cost
decimal tires; // Monthly tire cost
decimal maintenance; // Monthly maintenance cost
decimal monthlyCost; // Monthly total cost
try
{
loan = decimal.Parse(loanTextBox.Text);
insurance = decimal.Parse(insTextBox.Text);
gas = decimal.Parse(gasTextBox.Text);
oil = decimal.Parse(oilTextBox.Text);
tires = decimal.Parse(tiresTextBox.Text);
maintenance = decimal.Parse(mainTextBox.Text);
monthlyCost = loan + insurance + gas + oil + tires + maintenance;
TotalMonthlyLabel.Text = monthlyCost.ToString();// Display the monthlyCost in the correct control.
}
catch { }
試試這個,我刪除了一個變量,因為該變量不會讀取它只顯示值的值。
decimal loan; // Monthly cost of loan
decimal insurance; // Monthly insurance cost
decimal gas; // Monthly gas cost
decimal oil; // Monthly oil cost
decimal tires; // Monthly tire cost
decimal maintenance; // Monthly maintenance cost
decimal monthlyCost; // Monthly total cost
// Get the loan amount.
loan = decimal.Parse(loanTextBox.Text);
// Get the insurance amount.
insurance = decimal.Parse(insTextBox.Text);
// Get the gas amount.
gas = decimal.Parse(gasTextBox.Text);
// Get the oil amount.
oil = decimal.Parse(oilTextBox.Text);
// get the tires amount.
tires = decimal.Parse(tiresTextBox.Text);
// Get the maintenance amount.
maintenance = decimal.Parse(mainTextBox.Text);
// determine the monthly cost.
// Calculate monthly cost.
monthlyCost = loan + insurance + gas + oil + tires + maintenance;
totalMonthlyLabel.Text = monthlyCost.ToString();
您必須從您的用戶那里獲得不同類型的每月費用(這將是您的輸入)。 然后你的程序應該對該輸入執行一些計算以獲得一些輸出(即在你的情況下為monthlyCost
)。 您不必從您的用戶獲得monthlyCost
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.