Answers for "user input golang"

Go
3

user input golang

import (
"fmt"
"bufio"
)

//reading an integer
var age int
fmt.Println("What is your age?") // Question to the user
_, err: fmt.Scan(&age)

//reading a string
reader := bufio.newReader(os.Stdin)
var name string
fmt.Println("What is your name?") // Question to the user
name, _ := reader.readString('\n')

fmt.Println("Your name is ", name, " and you are age ", age)
}
Posted by: Guest on March-03-2020

Browse Popular Code Answers by Language