0% found this document useful (0 votes)
9 views3 pages

Tax Calculator Program Documentation

This document provides documentation for a C# program that calculates tax on an item. It: 1) Defines variables at the beginning with descriptive names and comments their purpose. 2) Gets user input for price and tax selection with error handling. 3) Uses if/else and switch statements to calculate GST, PST, or total tax depending on the user's selection. 4) Comments each section to explain the program flow and purpose.

Uploaded by

godzilla3456
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Tax Calculator Program Documentation

This document provides documentation for a C# program that calculates tax on an item. It: 1) Defines variables at the beginning with descriptive names and comments their purpose. 2) Gets user input for price and tax selection with error handling. 3) Uses if/else and switch statements to calculate GST, PST, or total tax depending on the user's selection. 4) Comments each section to explain the program flow and purpose.

Uploaded by

godzilla3456
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Documentation Example for Lab 2

//*********************************************************************************** //Program: [Link] //Description: Inputs the price of an item to purchase. Calculates and displays // GST, PST, or total tax due. Demonstrates if-else and switch. //Lab: 2 //Date: Oct. 06/2008 Program Block contains //Author: JD Blowhard //Course: CNT157 information shown using //Class: NET11 the example format //Instructor: JD Silver //*********************************************************************************** using System; namespace IfSwitch { class IfSwitch { const double kdGST = 0.05; const double kdPST = 0.06;

Variables use descriptive names, Hungarian notation and Camel case


//current GST rate //mythical PST rate

All variables defined at beginning of Main Purpose of each variable is commented Minimal number of variables are used

static void Main(string[] args) { double dPrice; //price of item entered by user string sTaxSelection; //tax calculation selection double dTaxTotal; //total tax calculated

//display title and explaination to user [Link]("\t\tTax Calculator\n"); [Link]("Input the price of an item to purchase and I"); [Link]("will calculate the GST and PST due.\n"); //input the item price [Link]("Enter the price of the item: "); dPrice = [Link]([Link]());

Each major block of code is separated by an empty line and commented.

//check for a positive price value if (dPrice > 0.00) { //display selection menu [Link]("Select the tax to calculate...\n"); [Link]("\tg: GST at 5%."); [Link]("\tp: PST at 6%."); [Link]("\tt: Total tax due.\n"); //input the user's selection [Link]("Your selection: "); sTaxSelection = [Link](); //convert selection to lower case for easier switch sTaxSelection = [Link]();

Purpose of each decision is commented

Code within if and else is indented

//select tax to calculate Purpose of switch switch (sTaxSelection) commented { //calculate GST case "g": dTaxTotal = dPrice * kdGST; [Link]("GST due for {0:C} is {1:C}", dPrice, dTaxTotal); break;

is

Each case is commented //calculate PST case "p": and indented as shown dTaxTotal = dPrice * kdPST; [Link]("PST due for {0:C} is {1:C}", dPrice, dTaxTotal); break;
//calculate total of GST and PST case "t": dTaxTotal = dPrice * kdGST + dPrice * kdPST; [Link]("GST + PST due for {0:C} is {1:C}", dPrice, dTaxTotal); break;

//invalid menu selection default: [Link]("You have made an incorrect selection."); break; } } //negative price value was entered else [Link]("You have entered an invalid price."); //pause prior to exit [Link]("Press any key to exit: "); [Link](); } } }

Each else is commented and code indented

All programs pause at the end.

You might also like