My LOLCODE suggests a few new things:

HAI
CAN HAS STDIO?

VISIBLE "Welcome to the basic calculator."
I HAS A NUMBER1 IZ 0
I HAS A NUMBER2 IZ 0
I HAS A OPERATION IZ NOTHING
I HAS A LINE IZ NOTHING
I HAS A COMPLETE IZ NOTWORKZ0RZ
I HAS A RESULT IZ 0

VISIBLE SAME LINEZ "Try what: "
TXT ME A LINE

IZ MAGICZ ON LINE WITH /(\n) (.?) (\n)/ ACTUALLY WORKZ0RZ?
        NUMBER1 IZ MAGICZ1
        OPERATION IZ MAGICZ2
        NUMBER2 IZ MAGICZ3
        COMPLETE IZ WORKZ0RZ
        KTHXBYE
:(
        VISIBLE "Can not parse line."
        COMPLETE IZ NOT WORKZ0RZ
        KTHXBYE

IZ COMPLETE WORKZ0RZ?
        WTF IZ OPERATION?
                OMG +
                        RESULT IZ UP NUMBER1!!NUMBER2
                OMG -
                        RESULT IZ DOWN NUMBER1!!NUMBER2
                OMG *
                        RESULT IZ TIMEZ NUMBER1!!NUMBER2
                OMG /
                        RESULT IZ DIVIDEZ NUMBER1!!NUMBER2
        KTHXBYE
:(
        VISIBLE "Didn't work :("
        DIAF! 2 "This is dieing"

VISIBLE "Result is: " ANDZ RESULT ANDZ "."

KTHXBYE

VISIBLE SAME LINEZ: Not inserting a newline, like default VISIBLE seems to do.

MAGICZ ON <variable> WITH <regexp>: Run regexps on the variable. Return true/false. With () groupings, use MAGICZ1, MAGICZ2, MAGICZ3, MAGICZ4, etc.

ACTUALLY: In a condition, test to see if something (iz) equal.

WORKZ0RZ/NOT WORKZ0RZ: TRUE/FALSE, possibly NOTWORKZ0RZ instead of two words.

TIMEZ/DIVIDEZ: TIMEZ was used elsewhere, DIVIDEZ I just added.

DIAF: Die (in a fire). Exit. First (optional) variable is the exit code. Second (optional) variable is the message.

ANDZ: Append a variable into a string.


The OMG/WTF case statement is a thing of beauty. Maybe use WTFBBQ as the default (no case matched?) — Church Tucker, 2007/05/30 16:56

contributions/basic-calculator.txt · Last modified: 2007/05/30 16:59 by churchmouse
Recent changes RSS feed Creative Commons License Donate Driven by DokuWiki