I need an help to get out of a corner, because I don't understand the logic behind a problem I am having.
I need to ask multiple times a user input, so logically I am creating a function like:
func askstuff() {
fmt.Println("Write something:")
var input string
fmt.Scanln(&input)
}
now I need to get the user input into a variable from the main() function, but I have a non-declarative matter and a brain issue....in fact I was expecting to do something like, but it is wrong
func main() {
askstuff()
println askstuff(input)
}
I have been reading all posts and docs and I understood that instead of a function, I should use a declarative variable out of main(), in the body, before main(). It works like a charm only if there is an hard coded fixed value but it doesn't with Scanln interactive console input.
I need to execute so many time askstuff(), that it will drive me nut without a separate class/function, but I also need to close the input into a variable within main() function, out of askstuff() function, to be able to work on it.
I am 100% ok with an RTFM reply if you give me one example that doesn't use a fixed hard coded value but use a user console interaction by scanln.
All book examples never use a scanln input, always a fixed declarative variable out of main () in the body.
Am I running in a specific scanln limitation? is a design concept matter with my logic? or there are better ways?
Please don't just give me just the snippet on how to fix the matter, explain me where and why my logic is wrong, so to understand it and don't repeat the error in the future.