简体   繁体   English

添加用户定义的数据

[英]Adding User Defined data

First thing I want to say is that this is for my homework. 首先我想说的是这是我的作业。 I am not looking for the answer just assistance in figuring out what I am doing wrong. 我不是在寻找答案来帮助弄清楚我做错了什么。 This is my fist programming class and up till this point I have been doing great. 这是我的第一个编程课程,到目前为止我一直都很棒。 Now all of a sudden I am lost. 现在突然间我迷路了。

The Question: Create an application that lets the user enter the monthly costs of the following expenses incurred from operating his or her automobile: Loan payment, insurance, gas, oil, tires, and maintenance. 问题:创建一个应用程序,让用户输入运营其汽车所产生的以下费用的月度成本:贷款支付,保险,汽油,机油,轮胎和维护。 The program should then display the total monthly cost of these expenses and the total annual cost of these expenses. 然后,该计划应显示这些费用的每月总费用以及这些费用的年度总费用。

This is what I have built: 这就是我建立的:

private void totalMonthlyButton_Click(object sender, EventArgs e) { 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.

Any help on this is greatly appreciated. 非常感谢任何帮助。 Again I do not want the answer just some pointers of if I'm heading in the right direction, if I am completely off, where to go next etc. 如果我正朝着正确的方向前进,如果我完全关闭,下一步去哪里,我再也不想要答案。

Thank you everyone. 谢谢大家。

This is the best way that I can think of right now: 这是我现在能想到的最佳方式:

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 { }

Try this, I removed a variable because that variable does not read the value it just has to display the value. 试试这个,我删除了一个变量,因为该变量不会读取它只显示值的值。

        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();

You have to get different type of monthly expenses from your user (that will be your input). 您必须从您的用户那里获得不同类型的每月费用(这将是您的输入)。 Then your program is supposed to perform some calculations on that input in order to get some output (ie monthlyCost in your case). 然后你的程序应该对该输入执行一些计算以获得一些输出(即在你的情况下为monthlyCost )。 You don't have to get monthlyCost from your user. 您不必从您的用户获得monthlyCost

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM