I have a function to read a single float64 from stdin:
func readFloat() float64 {
scanner := bufio.NewScanner(os.Stdin)
for {
scanner.Scan()
in := scanner.Text()
n, err := strconv.ParseFloat(in, 64)
if err == nil {
return n
} else {
fmt.Println("ERROR:", err)
fmt.Print("\nPlease enter a valid number: ")
}
}
}
I would like to modify this to read two floating point numbers for e.g.
func main() {
fmt.Print("\nEnter x, y coordinates for point1: ")
x1, y1 := readFloat()
Problem I am facing is splitting scanner.Text()
. There is a function scanner.Split()
but cannot understand how to use it.
Any possible solutions would be helpful.