title: Calculating taxable income and tax rate using asp.net, html and c#
body: <p>My goal here is to compute the federal income tax based on the taxable income using asp.net, c# and html. Below is what I've coded so far. Summary: The user inputs annual income and number of dependents via text boxes. There is a $1000 deduction for every dependent. Taxable income = annual income – (number of dependents * 1000). I need to multiply the taxable income with the tax rate.</p>
  
  <p>I am having difficulties calculating this value of taxable income, and still need to code the calculate button to do it's job. </p>
  
  <pre><code>Taxable Income Range and Tax Rate:
  &gt;450000 -- 39.6%.
  &gt;378000 and &lt;=450000 -- 33%.
  &gt;192000 and &lt;=378000 -- 28%.
  &gt;71000 and &lt;=192000 -- 25%.
  &gt;15000 and &lt;=71000 -- 15%.
  &lt;=15000 -- 10%.
  
  &lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Form1.aspx.cs" Inherits="WebApplication1.Form1" %&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
          &lt;div style="TEXT-ALIGN: center"&gt;
             Enter your name here: &lt;asp:TextBox ID="name" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;&lt;br /&gt;
             Annual Income: &lt;asp:TextBox ID="income" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;&lt;br /&gt;
             Number of dependents: &lt;asp:TextBox ID="dependents" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;&lt;br /&gt;
      &lt;asp:Button ID="calculate" runat="server" Text="Calculate Tax" OnClick="calculate_Click" /&gt;
      &lt;br /&gt;&lt;br /&gt;        
            Total Tax: &lt;asp:TextBox ID="total" runat="server"&gt;&lt;/asp:TextBox&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here's the .cs, I also need to edit the _rates second to represent the table above of taxable income and tax rate.</p>
  
  <pre><code>namespace WebApplication1 {
  }
  public class IncomeTaxCalculator
  {
  protected List&lt;KeyValuePair&lt;double, int&gt;&gt; _rates = null;
  protected IncomeTaxCalculator()
  {
      // Load from database.
      _rates = new List&lt;KeyValuePair&lt;double, int&gt;&gt;();
      _rates.Add(new KeyValuePair&lt;double, int&gt;(.10, 15000));
      _rates.Add(new KeyValuePair&lt;double, int&gt;(.15, 15000));
      _rates.Add(new KeyValuePair&lt;double, int&gt;(.25, 71000));
      _rates.Add(new KeyValuePair&lt;double, int&gt;(.28, 192000));
      _rates.Add(new KeyValuePair&lt;double, int&gt;(.33, 378000));
      _rates.Add(new KeyValuePair&lt;double, int&gt;(.396, 450000));
  }
  public double Single(int income)
  {
      double tax = 0;
      for (int i = _rates.Count - 1; i &gt;= 0; i--)
      {
          if (income &gt; _rates[i].Value)
          {
              tax += (income - _rates[i].Value) * _rates[i].Key;
              income = _rates[i].Value;
          }
      }
      return tax;
  }
  // Singletone
  protected static IncomeTaxCalculator _instance = null;
  public static IncomeTaxCalculator Instance
  {
      get
      {
          if (_instance == null)
          {
              _instance = new IncomeTaxCalculator();
          }
          return _instance;
      }
  }
  }
  public partial class Form1 : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          Response.Write(IncomeTaxCalculator.Instance.Single(40000).ToString("C"));
      }
      protected void calculate_Click(object sender, EventArgs e)
      {
      } 
  } 
  </code></pre>