I am brand new to the Go programming language and I am trying to build a very simple calculator. The issues I am running into is if someone enters in 4+2
or 5/10
or 100-25
to the command line how do I grab the operator and operands out of this string in order to perform the equation?
This is what I have so far, but this just grabs the entire string
package main
import (
"bufio"
"fmt"
"os"
"stack" //stack code works perfectly
)
func main() {
// Read a line from stdin.
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
// fmt.Println(line)
//Separate the string based on operator and operands
// Push all of the characters onto the stack.
s := stack.New()
for i := 0; i < len(line); i++ {
if err := s.Push(line[i]); err != nil {
panic("Push failed")
}
}