Update calculator.go

This commit is contained in:
Instrye
2017-02-10 15:13:14 +08:00
committed by GitHub
parent b7ec4c2c23
commit e8d45acd31

View File

@@ -31,21 +31,23 @@ func main() {
i, _ := strconv.Atoi(token) i, _ := strconv.Atoi(token)
calc1.Push(i) calc1.Push(i)
case token == "+": case token == "+":
q := calc1.Pop() q, _ := calc1.Pop()
p := calc1.Pop() p, _ := calc1.Pop()
fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p + q) fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p.(int) + q.(int))
case token == "-": case token == "-":
q := calc1.Pop() q, _ := calc1.Pop()
p := calc1.Pop() p, _ := calc1.Pop()
fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p - q) fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p.(int) - q.(int))
case token == "*": case token == "*":
q := calc1.Pop() q, _ := calc1.Pop()
p := calc1.Pop() p, _ := calc1.Pop()
fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p * q) fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p.(int) * q.(int))
case token == "/": case token == "/":
q := calc1.Pop() q, _ := calc1.Pop()
p := calc1.Pop() p, _ := calc1.Pop()
fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p / q) fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p.(int) / q.(int))
default: default:
fmt.Println("No valid input") fmt.Println("No valid input")
} }