Calculating taxable income and tax rate using asp.net, html and c# -
my goal here compute federal income tax based on taxable income using asp.net, c# , html. below i've coded far. summary: user inputs annual income , number of dependents via text boxes. there $1000 deduction every dependent. taxable income = annual income – (number of dependents * 1000). need multiply taxable income tax rate.
i having difficulties calculating value of taxable income, , still need code calculate button it's job.
taxable income range , tax rate: >450000 -- 39.6%. >378000 , <=450000 -- 33%. >192000 , <=378000 -- 28%. >71000 , <=192000 -- 25%. >15000 , <=71000 -- 15%. <=15000 -- 10%. <%@ page language="c#" autoeventwireup="true" codebehind="form1.aspx.cs" inherits="webapplication1.form1" %> <!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> </head> <body> <form id="form1" runat="server"> <div style="text-align: center"> enter name here: <asp:textbox id="name" runat="server"></asp:textbox> <br /><br /> annual income: <asp:textbox id="income" runat="server"></asp:textbox> <br /><br /> number of dependents: <asp:textbox id="dependents" runat="server"></asp:textbox> <br /><br /> <asp:button id="calculate" runat="server" text="calculate tax" onclick="calculate_click" /> <br /><br /> total tax: <asp:textbox id="total" runat="server"></asp:textbox> </div> </form> </body> </html>
here's .cs, need edit _rates second represent table above of taxable income , tax rate.
namespace webapplication1 { } public class incometaxcalculator { protected list<keyvaluepair<double, int>> _rates = null; protected incometaxcalculator() { // load database. _rates = new list<keyvaluepair<double, int>>(); _rates.add(new keyvaluepair<double, int>(.10, 15000)); _rates.add(new keyvaluepair<double, int>(.15, 15000)); _rates.add(new keyvaluepair<double, int>(.25, 71000)); _rates.add(new keyvaluepair<double, int>(.28, 192000)); _rates.add(new keyvaluepair<double, int>(.33, 378000)); _rates.add(new keyvaluepair<double, int>(.396, 450000)); } public double single(int income) { double tax = 0; (int = _rates.count - 1; >= 0; i--) { if (income > _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 { { 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) { } }
form1 doesn't have instance
. might want to:
response.write(incometaxcalculator.instance.single(40000).tostring("c"));
Comments
Post a Comment