From e8d45acd312029caf0cc0fa9f81aeb11f61c8ca5 Mon Sep 17 00:00:00 2001 From: Instrye Date: Fri, 10 Feb 2017 15:13:14 +0800 Subject: [PATCH] Update calculator.go --- eBook/exercises/chapter_12/calculator.go | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/eBook/exercises/chapter_12/calculator.go b/eBook/exercises/chapter_12/calculator.go index 87b32fc..9f2b8fe 100755 --- a/eBook/exercises/chapter_12/calculator.go +++ b/eBook/exercises/chapter_12/calculator.go @@ -31,21 +31,23 @@ func main() { i, _ := strconv.Atoi(token) calc1.Push(i) case token == "+": - q := calc1.Pop() - p := calc1.Pop() - fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p + q) + q, _ := calc1.Pop() + p, _ := calc1.Pop() + fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p.(int) + q.(int)) case token == "-": - q := calc1.Pop() - p := calc1.Pop() - fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p - q) + q, _ := calc1.Pop() + p, _ := calc1.Pop() + fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p.(int) - q.(int)) + case token == "*": - q := calc1.Pop() - p := calc1.Pop() - fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p * q) + q, _ := calc1.Pop() + p, _ := calc1.Pop() + fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p.(int) * q.(int)) + case token == "/": - q := calc1.Pop() - p := calc1.Pop() - fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p / q) + q, _ := calc1.Pop() + p, _ := calc1.Pop() + fmt.Printf("The result of %d %s %d = %d\n", p, token, q, p.(int) / q.(int)) default: fmt.Println("No valid input") }