0% found this document useful (0 votes)
26 views

Documentation Example For Lab 2

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)
26 views

Documentation Example For Lab 2

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
You are on page 1/ 3

Documentation Example for Lab 2

//*********************************************************************************** //Program: IfSwitch.cs //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 Console.WriteLine("\t\tTax Calculator\n"); Console.WriteLine("Input the price of an item to purchase and I"); Console.WriteLine("will calculate the GST and PST due.\n"); //input the item price Console.Write("Enter the price of the item: "); dPrice = double.Parse(Console.ReadLine());

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 Console.WriteLine("Select the tax to calculate...\n"); Console.WriteLine("\tg: GST at 5%."); Console.WriteLine("\tp: PST at 6%."); Console.WriteLine("\tt: Total tax due.\n"); //input the user's selection Console.Write("Your selection: "); sTaxSelection = Console.ReadLine(); //convert selection to lower case for easier switch sTaxSelection = sTaxSelection.ToLower();

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; Console.WriteLine("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; Console.WriteLine("PST due for {0:C} is {1:C}", dPrice, dTaxTotal); break;
//calculate total of GST and PST case "t": dTaxTotal = dPrice * kdGST + dPrice * kdPST; Console.WriteLine("GST + PST due for {0:C} is {1:C}", dPrice, dTaxTotal); break;

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

Each else is commented and code indented

All programs pause at the end.

You might also like