C#编程......帮助! [英] C# Programming... Help!

查看:69
本文介绍了C#编程......帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是论坛的新手,但我很难搞清楚如何创建项目。

我遵循指南来创建定价计算器。以下是指南:



H:带文字处理器和电子表格的99美元。每个附加程序49美元,例如演示文稿,出版商,网页编辑器等。最多允许安装五个。

E:带文字处理器,电子表格和演示文稿的249美元。每个额外计划99美元。此基本定价允许最多十个安装。每增加一次安装都会增加10%的额外费用。

U:999美元,包括所有程序和无限数量的安装。

必须输入客户类型,且必须是H,E和U之一。

如果客户类型为H或E,则用户可输入额外的数量程序(默认为零)。此数字不得为负数。

如果客户类型为E,则用户还可以输入安装数量(默认值为10)。这个数字必须是正数。如果安装数量超过40,请提醒用户无限制的计划更经济。

请帮助我..我很困惑。



这是我的代码:



  private   void  btnCalculate_Click( object  sender,EventArgs e)
{
const decimal U_CUST = 999 < /跨度>;
const decimal E_CUST = 249 ;
const decimal ADD_E_CUST = 99 ;
const decimal H_CUST = 99 ;
const decimal ADD_H_CUST = 49 ;

char CustType;
double AdditionalPrograms = 0 ;
double 安装= 0 ;
十进制比尔= 0 ;

if (txtCustType.Text ==
{
MessageBox.Show( 客户类型是必需的。,Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
txtCustType.Focus();
return ;
}
// 获取客户类型
CustType = .Parse(txtCustType.Text);
CustType = char .ToUpper(CustType);
txtCustType.Text = CustType.ToString();

// 检查并获取客户类型
if (CustType == ' U'
{
// Min:其他两个输入与'U'客户无关。

}

else if (CustType == ' H' || CustType == ' E'
{
// Min:获取第二个输入,如果已输入。
if (txtAddPrograms.Text == || txtInstallations .Text ==
{
AdditionalPrograms = double .Parse(txtAddPrograms.Text);
}

if (AdditionalPrograms < 0
{
MessageBox.Show( 其他程序的数量不得为负数。,Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
txtAddPrograms.Focus();
return ;
}
switch (CustType)
{
case ' U'
Bill = U_CUST;
break ;
case ' E'
if (安装< = 10
{
Bill = 249 +( 99 * AdditionalPrograms );
// MessageBox.Show(无限计划更经济。你想转换吗?, Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
if (Installations> 10)
{
Bill = E_CUST +(99 * AdditionalPrograms)+(AdditionalPrograms -10)*。 1 (E_CUST + 99 * AdditionalPrograms)
{
Bill =( decimal )(AdditionalPrograms)+(E_CUST)+(ADD_E_CUST)+( decimal )(安装*。 10 );
}
break ;
case ' H'
Bill =( decimal )(H_CUST)+(ADD_H_CUST *( decimal )AdditionalPrograms) ;

break ;
}

// 显示结果。
lblBill.Text = Bill.ToString( C);
}
}

解决方案

99,包含文字处理程序和电子表格。


< blockquote>每个附加程序49个,例如演示文稿,发布者,网页编辑器等。最多允许安装五个。

E:


249,带有文字处理器,电子表格和演示文稿。


I'm new to the forums, but I am having an extremely difficult time figuring out how to create a project.
I am following the guidelines to create a calculator for pricing. Here are the guidelines:

H: $99 with word processor and spreadsheet. $49 per additional program, such as presentation, publisher, web page editor, and the like. A maximum of five installations are allowed.
E: $249 with word processor, spreadsheet, and presentation. $99 per additional program. This basic pricing allows a maximum of ten installations. Every additional installation adds a 10% additional charge.
U: $999 with all programs included and unlimited number of installations.
Customer type must be entered and must be one of H, E, and U.
If the customer type is H or E, the user may enter the number of additional programs (default is zero). This number must not be negative.
If the customer type is E, the user may also enter the number of installations (default is ten). This number must be positive. If the number of installations is over 40, remind the user that the unlimited plan is more economic.
Please help me.. I am so stuck.

Here is my code:

private void btnCalculate_Click(object sender, EventArgs e)
{
    const decimal U_CUST = 999;
    const decimal E_CUST = 249;
    const decimal ADD_E_CUST = 99;
    const decimal H_CUST = 99;
    const decimal ADD_H_CUST = 49;

    char CustType;
    double AdditionalPrograms = 0;
    double Installations = 0;
    decimal Bill = 0;

    if (txtCustType.Text == "")
    {
        MessageBox.Show("Customer type is required.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
        txtCustType.Focus();
        return;
    }
    //get customer type
    CustType = char.Parse(txtCustType.Text);
    CustType = char.ToUpper(CustType);
    txtCustType.Text = CustType.ToString();

    //check and get customer type
    if (CustType == 'U')
    {
        // Min: the other two inputs are irrelevant for 'U' customer.
   
    }
   
    else if (CustType == 'H' || CustType == 'E')
    {
        // Min: get the second input, if it's entered.
        if (txtAddPrograms.Text == ""||txtInstallations .Text=="")
        {
            AdditionalPrograms = double.Parse(txtAddPrograms.Text);
        }

        if (AdditionalPrograms < 0)
        {
            MessageBox.Show("Number of Additional Programs must not be negative.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            txtAddPrograms.Focus();
            return;
        }
        switch (CustType)
        {
            case 'U':
                Bill = U_CUST;
                break;
            case 'E':
                if (Installations <=10) 
                {
                    Bill = 249 + (99 * AdditionalPrograms);
                    //MessageBox.Show("The Unlimited plan is more economic. Would you like to switch?", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                if (Installations>10)
                {
                    Bill=E_CUST +(99*AdditionalPrograms) +(AdditionalPrograms -10)*.1(E_CUST+99*AdditionalPrograms )
                {
                    Bill = (decimal)(AdditionalPrograms) + (E_CUST) + (ADD_E_CUST) + (decimal)(Installations * .10);
                }
                break;
            case 'H':
                Bill = (decimal)(H_CUST) + (ADD_H_CUST * (decimal)AdditionalPrograms);
               
                break;
        }

        //Display the result.
        lblBill.Text = Bill.ToString("C");
    }
}

解决方案

99 with word processor and spreadsheet.


49 per additional program, such as presentation, publisher, web page editor, and the like. A maximum of five installations are allowed.
E:


249 with word processor, spreadsheet, and presentation.


这篇关于C#编程......帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆