繁体   English   中英

添加用户定义的数据

[英]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.

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