add getln() function and calculator example
Runtime-allocated strings currently always leak memory, I will definitely have to fix that.
This commit is contained in:
22
examples/calculator.script
Normal file
22
examples/calculator.script
Normal file
@@ -0,0 +1,22 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user