Amanda Duffin

Amanda Duffin

  • NA
  • 2
  • 2.5k

C# program issue... new to C#

Sep 29 2013 2:40 AM
Hi,

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");
        }
    }
}

Answers (1)