I am using fmt.Scanln()
to read user’s input, the reader stops at newline, on previous case I use fmt.Scanf()
but it reads the first input and terminates.
This is part of an exercise for my golang tutorial.
package main import "fmt" func main(){ var weight float64 var height float64 fmt.Println("Your weight: ") fmt.Scanln(&weight) fmt.Println("Your height: ") fmt.Scanln(&height) switch bmi := getBMI(height, weight); { case bmi < 18.5: fmt.Printf("Your bmi is %.2f, and you are underweight.", bmi) case bmi < 25: fmt.Printf("Your bmi is %.2f, and your BMI is normal", bmi) case bmi < 30: fmt.Printf("Your bmi is %.2f, and you are overweight", bmi) default: fmt.Printf("Your bmi is %.2f, and you are obese.", bmi) } } func getBMI(height float64, weight float64) float64 { return weight / (height * height) }