# Creating FormPage Calculator with a Piecewise Function

I am trying to make a calculator to help my mom calculate late fees in our rental property business. Thus, in this calculator all you're supposed to do is input the date on which the tenant is paying and its supposed to spit back out their late fee. The late fee is calculated by the piecewise function that corresponds to our late fee rule in our lease agreements.

However, I am running into a problem. My current calculator doesn't spit back out a simple number. It spits back out a schedule of numbers showing what the output would be if the input was evaluated at any point in the function's domain...

...as you can see in this example. 10 obviously belongs to the 7 < x <= 14 part of the function, and the corresponding output late fee is correct when evaluated there, but how do I get the calculator to simply spit out a number instead of this weird collumn list thing? (The function works normal like this when I just evaluate it at f[10] without the FormPage stuff).

Here is the code I am using:

f[x_] :=
Piecewise[{{0, x <= 3}, {50 + 5 x - 20, 3 < x <= 7}, {100 + 5 x - 20,
7 < x <= 14}, {200 + 5 x - 20, 14 < x}}]

FormPage["DatePaid" -> "Integer", f]


Thank you very much for your time.

Clear[f, x]
f[x_] := Piecewise[{
{0, x <= 3}
, {50 + 5 x - 20, 3 < x <= 7}
, {100 + 5 x - 20, 7 < x <= 14}
, {200 + 5 x - 20, 14 < x}
}
]

FormPage["DatePaid" -> "Integer", f[#DatePaid] &]


If you insist on using String data type then:

FormPage["DatePaid" -> "String", f[ToExpression@#DatePaid] &]

• That works. Thank you very much Syed. Much appreciated.
– SDH
Dec 3, 2022 at 18:20