Created
June 28, 2015 17:40
-
-
Save Learath2/f1cc87187de85273205f to your computer and use it in GitHub Desktop.
Calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from strutils import replace,find,parseInt | |
echo("Input an operation:") | |
var line = readLine(stdin) | |
line = replace(line, " ", ""); | |
let | |
opindex = find(line, {'+','-','*','/'}) | |
op = line[opindex] | |
arg1 = parseInt(line[0..opindex-1]) | |
arg2 = parseInt(line[opindex+1..high(line)]) | |
var result: int = 0 | |
case op | |
of '+': | |
result = arg1 + arg2 | |
of '-': | |
result = arg1 - arg2 | |
of '*': | |
result = arg1 * arg2 | |
of '/': | |
result = (arg1 / arg2).int | |
else: | |
discard | |
echo("Result = ", result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment