Net Price Calculation

Introduction

Items in a department store or any other store usually display the price of an item. Customers take such an item to the cashier who rings it, applies the tax rate and present the total price to the customer.

The marked price, the price presented on an item, is in currency value. Wn example would be $120.95

The tax rate is expressed as a percentage value. An example would be 5.75%

The computer used to evaluate the price use a formula such as:

Tax Amount = Marked Price / Tax Rate

The net price, the actual price a customer should pay, is calculated as:

Net Price = Marked Price + Tax Amount

In this exercise, we will simulate such a calculation

Starting the Application

  1. Start Microsoft Visual Studio or Microsoft Visual C#.
  2. On the main page, click the New Project button
  3. In the New Project Dialog Box, in the Project Types section, click Visual C# and, in the Templates section, click Windows Application
  4. Set the Name to Net Price
     
  5. Click OK
 

Designing the Application

  1. While the form is still selected, in the Properties window, change the FormBorderStyle to FixedDialog
  2. Change the Text field to Net Price Calculation
  3. Set the Minimize Box and the Maximize Box to False
  4. Design the dialog box as follows:
     
  5. Set the names of the TextBox and Button controls from top to button to
    TextBox Name Text Button Name Caption
    txtMarkedPrice 0.00 btnCalculate C&alculate
    txtTaxRate 0.00 btnClose &Close
    txtTaxAmount 0.00    
    txtNetPrice 0.00    
  6. Save your application.

Programming the Application

  1. On the form, double-click the Close button and implement its event as follows:
     
    private void btnClose_Click(object sender, System.EventArgs e)
    {
    	Close();
    }
  2. Return the form. Double-click the Calculate button and implement its event as follows:
     
    private void btnCalculate_Click(object sender, System.EventArgs e)
    {
    	double MarkedPrice, TaxRate, TaxAmount, NetPrice;
    
    	MarkedPrice = double.Parse(txtMarkedPrice.Text);
    	TaxRate		= double.Parse(txtTaxRate.Text);
    	
    	TaxAmount	= MarkedPrice * TaxRate / 100;
    	NetPrice	= MarkedPrice + TaxAmount;
    
    	txtTaxAmount.Text = TaxAmount.ToString("C");
    	txtNetPrice.Text  = NetPrice.ToString("C");
    }
  3. Test your program.

 

 

Copyright © 2003-2015, FunctionX, Inc. FunctionX