Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Help with "Taking User Input" in golang

Hi everyone, Hope you are all well. I've been struggling with Taking User Input in Go Lang.

Here is my code


package main

import (
"fmt"
"bufio"
"os"
)

func main() {
fmt.Println("Enter a number:")
reader := bufio.NewReader(os.Stdin)
userInput, _ := reader.ReadString('\n')
fmt.Println(userInput)
}
by

2 Answers

sam5epi0l
Your code seems right. Please attach the error you got.
iamabhishek
You do not have to write the correct code. I think the instructions can be improved a little.
As you haven't learned about the _ as of Lesson 1 of Level 5 so you don't have to use it. This program should give an error because you will learn about using _ to handle response and error in the coming lessons.

Try this code:


package main

import (
"fmt"
"bufio"
"os"
)

func main() {
fmt.Println("Enter a number:")
reader := bufio.NewReader(os.Stdin)
userInput := reader.ReadString('\n')
fmt.Println(userInput)
}

Login / Signup to Answer the Question.