c# - Defining a taxRate and applying it to a user's inputted annual income -
taxrate not exist in current context. how can apply if/else if statements?
<!doctype html> <head runat="server"> </head> <body> <form id="form1" name="form1" runat="server"> <div style="text-align: center"> 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>
taxrate problem is, have double , initial value 1. going problem? getting warning saying value never used.
namespace webapplication1 { public partial class form1 : system.web.ui.page { protected void page_load(object sender, eventargs e) { } protected void calculate_click(object sender, eventargs e) { int num1 = int32.parse(income.text); int num2 = int32.parse(dependents.text); int taxableincome = num1 - (num2 * 1000); double taxrate = 1; if (taxableincome <= 15000) taxrate = 0.10; else if (taxableincome <= 71000 && taxableincome > 15000) taxrate = 0.15; else if (taxableincome <= 192000 && taxableincome > 71000) taxrate = 0.25; else if (taxableincome <= 378000 && taxableincome > 192000) taxrate = 0.28; else if (taxableincome <= 450000 && taxableincome > 378000) taxrate = 0.33; else if (taxableincome > 450000) taxrate = 0.396; total.text = taxableincome.tostring(); } } }
you need declare taxrate in method able use it.
protected void calculate_click(object sender, eventargs e) { decimal taxrate = 1; // if statements here // use taxrate whatever else here. }
Comments
Post a Comment