mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
30 lines
767 B
Plaintext
Executable File
30 lines
767 B
Plaintext
Executable File
"- Calculator -".println
|
|
"Type =<num> to set the value to that number.".println
|
|
"Type +<num>, -<num>, *<num> or /<num> to change the value.".println
|
|
"Type exit to exit.".println
|
|
|
|
current := 0.0
|
|
|
|
().loop(() -> {
|
|
("[ ", current, " ]").concat.println
|
|
input := ().read_line.trim
|
|
num := (input, 1).substring.trim.parse_float.try((
|
|
() -> 0.0,
|
|
val -> val
|
|
))
|
|
mode := input.substring(0, 1)
|
|
if mode.eq("+") {
|
|
¤t = (current, num).sum
|
|
} else if mode.eq("-") {
|
|
¤t = (current, (num, -1).product).sum
|
|
} else if mode.eq("*") {
|
|
¤t = (current, num).product
|
|
} else if mode.eq("/") {
|
|
¤t = (current, num).div
|
|
} else if mode.eq("=") {
|
|
¤t = num
|
|
} else if (input.eq("exit"), input.eq("")).any {
|
|
(())
|
|
}
|
|
})
|