2
$\begingroup$

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...

Piecewise Function Late Fee Calculator

...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.

$\endgroup$

1 Answer 1

3
$\begingroup$
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] &]

enter image description here


If you insist on using String data type then:

FormPage["DatePaid" -> "String", f[ToExpression@#DatePaid] &]
$\endgroup$
1
  • 1
    $\begingroup$ That works. Thank you very much Syed. Much appreciated. $\endgroup$
    – SDH
    Dec 3, 2022 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.