實作按下 . 要怎麼處理

This commit is contained in:
2020-05-06 06:41:05 +08:00
parent 4bbf187cd2
commit 160f1ebd9f

View File

@@ -47,6 +47,15 @@ class Calculator {
formula.append(formula.popLast()! + text)
}
case ".":
if formula.last!.firstIndex(of: ".") != nil {
return
} else if ["+", "-", "×", "÷"].firstIndex(of: formula.last!) != nil {
return
} else {
formula.append(formula.popLast()! + text)
}
default:
print(formula)
}