GO:我正在尝试猜测我的号码,但是我的程序无法正确解释数字

package main

import "fmt"
import bf "bufio"
import "os"
import "strconv"

type SVC int

func main() {
        fmt.Println("Loaded")
        var gmber = bf.NewScanner(os.Stdin)
        gmber.Scan()
        i := 1
        for i < 40 {
                fmt.Println("
")
                i++
        }
        var input2 = bf.NewScanner(os.Stdin)
        fmt.Println("Make a guess:")
        var input21, err = strconv.Atoi(input2.Text())
        var gmber1, err0 = strconv.Atoi(gmber.Text())
        input2.Scan()
        for {
                if input21 == gmber1{
                        break
                }
                if input21 > gmber1 {
                        fmt.Println("Too high, Guess again")
                        input2.Scan()
                }
                if input21 < gmber1 {
                        fmt.Println("Too low, Guess again")
                        input2.Scan()
                }
        }
        fmt.Println("You win!")
        fmt.Println(err)
        fmt.Println(err0)
}

I when I run this program, my program will always spit out "Too low, Guess again". I input: 100 as the number to be guessed, then guessed the number 101, and it said too low. I just do not really know what to do now, does anybody understand why this program does this? NOTES: input21 is ALWAYS=to 0

You need to understand how type Scanner works. Read the documentation for type Scanner and its methods carefully and take a look at the examples.

package bufio: type Scanner

For example, "Scan advances the Scanner to the next token, which will then be available through the Bytes or Text method."

For buffered stream input, it's dangerous to have more than one scanner per file.

It's no fun to guess a number that you input yourself. Use a random number generator, for example, 'package math/rand`.

It would take too long to explain all the problems with your code, so here's a simple example,

package main

import (
    "bufio"
    "fmt"
    "math/rand"
    "os"
    "strconv"
    "time"
)

func main() {
    rand.Seed(time.Now().UnixNano())
    var number = rand.Intn(100)
    fmt.Println("Make a guess:")
    var scanner = bufio.NewScanner(os.Stdin)
    for scanner.Scan() {
        var guess, err = strconv.Atoi(scanner.Text())
        if err != nil {
            fmt.Print("Input error")
        } else if guess == number {
            break
        } else if guess > number {
            fmt.Print("Too high")
        } else if guess < number {
            fmt.Print("Too low")
        }
        fmt.Println(", Guess again:")
    }
    if scanner.Err() != nil {
        fmt.Println("I give up!")
    }
    fmt.Println("You win!")
}

Whenever you have a function that returns an error value, you must check whether that is nil. Only after you have done that may you access any other value that the function returned.

When you add this proper error handling, you will see where your program fails.

I was not resetting the scanners, at the end of the if's where the scanner is re-evaluated, you have to re-declare the strconv.Atoi