我想说的第一件事是这是我的功课。我不是在寻找答案来帮助弄清楚我做错了什么。这是我的第一个编程课程,到目前为止我一直都很棒。现在突然间我迷失了。
问题: 创建一个应用程序,让用户输入运营其汽车所产生的以下费用的每月费用:贷款支付,保险,汽油,机油,轮胎和维护。然后,该计划应显示这些费用的每月总费用以及这些费用的年度总费用。
这就是我建立的:
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.
非常感谢任何帮助。如果我正朝着正确的方向前进,如果我完全关闭,下一步去哪里等,我再也不想要答案。
谢谢大家。
答案 0 :(得分:2)
这是我现在能想到的最佳方式:
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 { }
答案 1 :(得分:1)
试试这个,我删除了一个变量,因为该变量不会读取它只显示值的值。
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();
答案 2 :(得分:0)
您必须从用户那里获得不同类型的每月费用(这将是您的输入)。然后你的程序应该对该输入执行一些计算以获得一些输出(即你的情况下为monthlyCost
)。您无需从用户那里获得monthlyCost
。