Wednesday, April 23, 2014

Radio Button Exercise 2


namespace Zau_RadioButton_Exercise_2
{

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            string paymentmethod = String.Empty;
            double price = 0;
            double.TryParse(txtTicketPrice.Text, out price);

            if (radCash.Checked)
                paymentmethod = "Cash";
            else if (radCheck.Checked)
                paymentmethod = "Check";
            else if (radCredit.Checked)
                paymentmethod = "Credit";

            double discount = 0;
            if (rad10.Checked)
                discount = 0.1;
            else if (rad25.Checked)
                discount = 0.25;
            else if (rad35.Checked)
                discount = 0.35;

            double subtotal = price * (1 - discount);
            double tax = subtotal * 0.098;
            double totalcost = subtotal + tax;

            txtPayment.Text = paymentmethod;
            txtTax.Text = tax.ToString("c");
            txtTotalCost.Text = totalcost.ToString("c");
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}

No comments:

Post a Comment