Skip to content

Commit

Permalink
Update calculator.go
Browse files Browse the repository at this point in the history
  • Loading branch information
nyufeng committed Feb 10, 2017
1 parent b7ec4c2 commit e8d45ac
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions eBook/exercises/chapter_12/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit e8d45ac

Please sign in to comment.