-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmi.go
44 lines (39 loc) · 865 Bytes
/
bmi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
"strings"
)
func main() {
for {
reader := bufio.NewReader(os.Stdin)
fmt.Println("Please input your height")
height_text, _ := reader.ReadString('\n')
height_text = strings.TrimRight(height_text, "\n")
if height_text == "end" || height_text == "quit" {
break
}
height, err := strconv.ParseFloat(height_text, 64)
if err != nil {
continue
}
if height >= 10 {
height /= 100
}
fmt.Println("Please input your weight")
weight_text, _ := reader.ReadString('\n')
weight_text = strings.TrimRight(weight_text, "\n")
if weight_text == "end" || weight_text == "quit" {
break
}
weight, err := strconv.ParseFloat(weight_text, 64)
if err != nil {
continue
}
bmi := weight / math.Pow(height, 2)
fmt.Println("\n" + "Your BMI is " + fmt.Sprintln(bmi))
}
}