Course of Raku / Advanced / Operators / User-defined operators / Exercises
Percent-of operator
Problem
Define an infix operator percent-of so that the
expression $p percent-of $whole returns $p per
cent of $whole. For example, 20 percent-of 150
is 30.
Use the operator to print 20 percent-of 150.
Example
The program prints:
30Solution
Course navigation
← Solution: Average operator | Solution: Percent-of operator →