' Optional Params — parameter handling with defaults
#COMPILE EXE
#DIM ALL

FUNCTION MakeGreeting(BYVAL sName AS STRING, BYVAL greeting AS STRING) AS STRING
    FUNCTION = greeting + ", " + sName + "!"
END FUNCTION

FUNCTION Power(BYVAL base AS DOUBLE, BYVAL exponent AS DOUBLE) AS DOUBLE
    LOCAL r AS DOUBLE
    LOCAL i AS LONG
    r = 1.0
    FOR i = 1 TO exponent
        r = r * base
    NEXT i
    FUNCTION = r
END FUNCTION

FUNCTION PBMAIN() AS LONG
    LOCAL r1 AS STRING
    LOCAL r2 AS STRING
    LOCAL r3 AS STRING
    LOCAL p1 AS DOUBLE
    LOCAL p2 AS DOUBLE
    LOCAL p3 AS DOUBLE

    r1 = MakeGreeting("Alice", "Hello")
    PRINT "MakeGreeting(Alice): " + r1
    r2 = MakeGreeting("Bob", "Hi")
    PRINT "MakeGreeting(Bob,Hi): " + r2
    r3 = MakeGreeting("Carol", "Good day")
    PRINT "MakeGreeting(Carol,Good day): " + r3
    PRINT
    p1 = Power(5.0, 2.0)
    PRINT "Power(5.0, 2): " + STR$(p1)
    p2 = Power(2.0, 3.0)
    PRINT "Power(2.0, 3): " + STR$(p2)
    p3 = Power(3.0, 4.0)
    PRINT "Power(3.0, 4): " + STR$(p3)

    FUNCTION = 0
END FUNCTION
