CLEAR ALL
PRINT LINE CENTER "FACTORIALS",,RGB(255,0,0)
DO
    PRINT
    INPUT "Enter a number between 1 and 15, or 0 to exit: ",n
    IF n=0 THEN
        PRINT "Goodbye!"
        EXIT DO
    ELSE IF n>=1 AND n<=15 THEN
        PRINT "The factorial of "+STR$(n)+" is "+STR$(Fact(n))
    ELSE
        PRINT "Invalid number!"
    END IF
LOOP
END
FUNCTION Fact(n)
    IF n=0 THEN
        Fact=1
    ELSE
        Fact=n*Fact(n-1)
    END IF
END FUNCTION
