Sale Price Calculator

74 Views

salesPrice

// Gaddis Code from text with slight mods (Wyatt)
//
// Terry T Trainer CIS 202 3/22/2013
/* Calculates Sale Price of Item from Price and Discount %
    
      get price -  must Parse!
      get discount % - must Parse!
      calculate calculate discount
      calculate sale price = price - discount
      display sales price $
*/
using System;
using System.Windows.Forms;
namespace Sale_Price_Calculator
{
    public partial class Form1 : Form
    {
        // Automated: Creates the GUI from designer input    
        public Form1() { InitializeComponent(); }
        // Calculate the Sale Price
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            // Local Variables       
            double originalPrice, discountPercentage,  discountAmount, salePrice;   
            // Get item's original price.
            originalPrice = double.Parse(txtOriginalPrice.Text);
            // Get discount percentage.
            discountPercentage = double.Parse(txtDiscountPercentage.Text);
            // Create decimal representation of %  (move point left two places)
            discountPercentage = discountPercentage / 100;
            // Calculate amount of the discount.
            discountAmount = originalPrice * discountPercentage;
            // Calculate sale price.
            salePrice = originalPrice - discountAmount;
            // Display sale price as Currency ("c")
            lblSalePrice.Text = salePrice.ToString("c");
        }
        // End
        private void btnExit_Click(object sender, EventArgs e)
        {
            // Close the form.
            this.Close();
        }
    }
}

Leave a Reply

Your email address will not be published.

Skip to toolbar