【发布时间】:2015-02-07 16:54:03
【问题描述】:
首先我想说的是,这是我的作业。我不是在寻找答案,只是帮助找出我做错了什么。这是我的第一个编程课,到目前为止我一直做得很好。现在突然间我迷路了。
问题: 创建一个应用程序,让用户输入运营他或她的汽车所产生的以下费用的每月成本:贷款支付、保险、汽油、机油、轮胎和维护。然后程序应显示这些费用的每月总成本和这些费用的年度总成本。
这是我构建的:
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.
非常感谢您对此的任何帮助。再说一次,我不希望只是一些提示,如果我朝着正确的方向前进,如果我完全离开,下一步要去哪里等等。
谢谢大家。
【问题讨论】:
-
我能给初学者的最佳建议是减少您编写的 cmets 的数量。您的 vars\methods 应该足够清楚。你的问题在哪里?您想将每月总费用插入文本框吗?
-
monthlyCost 不应该被解析,因为这是你最终想要的变量。完成添加后,只需在 MessageBox 左右显示结果(monthlyCost)。不要忘记使用 .ToString() 方法。
-
您的代码看起来不错。如果要将
monthlyCost十进制变量转换为String,请使用monthlyCost.ToString()并将其插入正确的文本框 -
是的,我构建它的方式是用户将在那里输入信息到文本框中,然后答案将填充到标签中。到目前为止,我没有显示任何错误,但是当我尝试告诉程序在哪里显示monthlyCost 时,我放在那里的所有内容都会导致错误。
-
你是否包括了你如何“试图告诉程序在哪里显示”?我没有看到那部分。随意edit那在
标签: c#