lang/examples/calculator.script
r4 dfe1ac90e8 add getln() function and calculator example
Runtime-allocated strings currently always leak memory, I will
definitely have to fix that.
2021-12-26 11:36:52 +01:00

23 lines
432 B
Plaintext

put("Enter an operation (+, -, *, /): ")
op := getln()
if (!(op == "+" || op == "-" || op == "*" || op == "/")) {
put("Unknown operation: ")
putln(op)
} else {
put("1st number: ")
n1 := float(getln())
put("2nd number: ")
n2 := float(getln())
put("Result: ")
if (op == "+") {
putln(n1 + n2)
} else if (op == "-") {
putln(n1 - n2)
} else if (op == "*") {
putln(n1 * n2)
} else if (op == "/") {
putln(n1 / n2)
}
}