Skip to content

Compute a Tax Amount

Enter Code

Enter the following code in a file named ‘Compute.cs’:

using System;
using TaxControls;
class Compute{
public static void Main(){
try {
CTaxControl tc = new CTaxControl();
tc.DataFilename = "demo.tax";
tc.SelectedTax = "federal income tax";
tc.Earnings = 5000.00;
Console.WriteLine(tc.TaxAmount());
} catch (TaxControlException e) {
Console.WriteLine(e.Message);
}
}
}

This minimal code chooses the tax table data file, sets the earnings per pay period to $5000, and computes the tax. Default values were taken, which for most properties is zero, except PayPeriodsPerYear which defaults to 12 (monthly).

Compile

Compile the code at the command prompt by executing the following:

Terminal window
csc /reference:TaxControls.dll Compute.cs

Run

Run the code by typing:

Terminal window
Compute

The program’s output should show the computed federal tax.