Documentation Example For Lab 2
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;
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());
//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();
//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(); } } }