Taking input cause misbehavior
Closed this issue · 1 comments
Sddilora commented
in https://github.com/johsquaree/goo/blob/master/dice-game/dice-game.go, I guess the problem is still caused by fmt package's Scan function. I tried to use bufioScanner and it worked.
reader := bufio.NewReader(os.Stdin)
fmt.Printf("Mavi Takim Ilk Indexinizi Seciniz:\n")
stringB, _ := reader.ReadString('\n')
fmt.Printf("Kirmizi Takim Ilk Indexinizi Seciniz:\n")
stringR, _ := reader.ReadString('\n')
time.Sleep(time.Second * 1)
a := 0
b, _ := strconv.Atoi(stringB)
r, _ := strconv.Atoi(stringR)
Sddilora commented
By the way, it's currently functioning correctly, but there's a non-nil error being reported.
Remember Rule 101: "If it is work don't touch it."
The error messages you're seeing indicate issues with parsing the input values "4\r\n" and "8\r\n" using strconv.Atoi.
b, err := strconv.Atoi(stringB)
if err != nil {
fmt.Println(err)
}
r, err:= strconv.Atoi(stringR)
if err != nil {
fmt.Println(err)
}
( 4 and 8 as input )
strconv.ParseInt: parsing "4\r\n": invalid syntax
strconv.ParseUint: parsing "8\r\n": invalid syntax