// Needs to be in a class as no concept of 'global' variables
class tipCalculator
{
class var rates = new dict[[["terrible", 0 percent],
["poor", 5 percent],
["good", 10 percent],
["great", 15 percent],
["excellent", 20 percent]]]
class calc[amount, rating] :=
{
r = lc[rating]
if not rates.containsKey[r]
return -1
return ceil[amount * rates@r]
}
}
println[tipCalculator.calc[30,"poor"]] // 2
println[tipCalculator.calc[20, "hi"]] // -1
println[tipCalculator.calc[107.65, "great"]] // 17
println[tipCalculator.calc[78, "good"]] // 8
println[tipCalculator.calc[50, "poor"]] // 3
println[tipCalculator.calc[125, "excellent"]] // 25
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Implementation in Frink