package main import "fmt" func main() { fmt.Println("Welcome to Go Bank!") fmt.Println("What do you want to do?") fmt.Println("1. Check balance") fmt.Println("2. Deposit money") fmt.Println("3. Withdraw money") fmt.Println("4. Exit") var choice int fmt.Scan(&choice) fmt.Println("Your choice:", choice) }

package main import ( "fmt" "os" ) func main() { var investmentAmount float64 fmt.Print("Investment Amount: ") _, err := fmt.Scanln(&investmentAmount) if err != nil { fmt.Println("Invalid input. Please input a number then press enter.") os.Exit(1) } }

package main import ( "bufio" "fmt" "os" "strings" ) func main() { fmt.Println("Welcome to Go Bank!") fmt.Println("What do you want to do?") fmt.Println("1. Check balance") fmt.Println("2. Deposit money") fmt.Println("3. Withdraw money") fmt.Println("4. Exit") reader := bufio.NewReader(os.Stdin) text, err := reader.ReadString('\n') if err != nil { fmt.Println(err) return } text = strings.TrimSuffix(text, "\n") text = strings.TrimSuffix(text, "\r") fmt.Printf("Your choice: %v\n", text) }


浙公网安备 33010602011771号