Wolfram Language

Cloud & Web Interfaces

Create a Web Form to Compute the Marginal Tax Rate

In many cases, the computations related to taxes are too complex to be effectively embedded in a single web form. AskFunction allows you to express the computation in a simple and intuitive way.

In[1]:=
Click for copyable input
CloudDeploy[AskFunction[Module[{bracket, tax, income}, bracket = Ask[{"brackets", "What is your marital status?"} -> {"Married filing jointly" \ -> {18550, 75300, 151900, 231450, 413350, 466950}, "Single" -> {9275, 37650, 91150, 190150, 413350, 415050}, "Head of household" -> {13250, 50400, 130150, 210800, 413350, 441000}, "Married filing separately" -> {9275, 37650, 75950, 115725, 206675, 233475}}]; income = Ask[{"income", "What was your income in 2015"} -> Restricted["Number", {0, Infinity}]]; tax = Integrate[ Piecewise[{{.10 , 0 <= x <= bracket[[1]]}, {.15, bracket[[1]] < x <= bracket[[2]]}, {.25, bracket[[2]] < x <= bracket[[3]]}, {.28, bracket[[3]] < x <= bracket[[4]]}, {.33, bracket[[4]] < x <= bracket[[5]]}, {.35, bracket[[5]] < x <= bracket[[6]]}, {.396, True}}], {x, 0, income - If[Ask[{"deps", "Do you have any dependents?"} -> {"Yes" -> True, "No" -> False}], Ask[{"nodeps", "How many?"} -> Restricted["Integer", {0, Infinity}]]* 4050, 0]}]; AskTemplateDisplay[ Column[{"You owe $" <> ToString[tax] <> " in taxes.", "Your marginal tax rate is " <> ToString[Round[100.*tax/#income, 0.1]] <> "%", PieChart[{tax, income}]}] &] ]]]
Out[1]=

As you can see in this example, you can use the programming style you prefer, using Module and storing the state of your computation. AskFunction will also skip questions that are not needed. Try it for yourself.

Related Examples

de es fr ja ko pt-br ru zh