Invoice Total

                                                                    Note:  No protection against bad numeric input.
                                                              Note:  Some conditions use relational AND logical operators.

// Code from text with slight mods (Wyatt)
//
// Terry T Trainer CIS 202 3/22/2013
/* 
   GET USER TYPE ** CHANGE (R or C)
   get amount from user
   calculate discount amount 
   calculate total 
   display
*/
using System;
using System.Windows.Forms;

namespace InvoiceTotal
{
   public partial class frmInvoiceTotal : Form
   {
      // Creates the GUI - this code is added by the system
      public frmInvoiceTotal()
      {
         InitializeComponent();
      }

      // calculates the discount and the invoice total
      private void btnCalculate_Click(object sender, EventArgs e)
      {
         // declare variables to store data and information
         double subtotal;
         double discountPercent; 
         double discountAmount;
         double invoiceTotal;
         string customerType;
         
         // read customer type (R or C)
         customerType = txtCustomerType.Text;
         
         // read the subtotal from text box and convert string to a number
         subtotal = double.Parse(txtSubtotal.Text);

         // calculate discount based on customer type and amount
         if (customerType == "R")
         {
            if (subtotal < 100)
               discountPercent = .0;
            else if (subtotal >= 100 && subtotal < 250)
               discountPercent = .1;
            else if (subtotal >= 250)
               discountPercent = .25;
         }
         else if (customerType == "C")
         {
            if (subtotal < 250)
               discountPercent = .2;
            else
               discountPercent = .3;
         }
         else
         {
            discountPercent = .4;
         }           
         
         // calculate the discount and total
         discountAmount = subtotal * discountPercent;
         invoiceTotal = subtotal - discountAmount;

         // output the information to the form
         txtDiscountPercent.Text = discountPercent.ToString("p1"); // 'p' means as a percent
         txtDiscountAmount.Text = discountAmount.ToString("c"); // 'c' means as curerency
         txtTotal.Text = invoiceTotal.ToString("c");

         // put the cursor back at textbox so next amount can easily be calculated
         txtCustomerType.Focus();
      }

      // exits the program
      private void btnExit_Click(object sender, EventArgs e)
      {
         this.Close();
      }
   }
}