-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmi.go
86 lines (70 loc) · 1.93 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
/*
*****************************************************************
@author: Adenugba Adeoluwa
Date: 9th November 2022
Purpose: To calculate the basic mass index of a user
********************************************************************
*/
import (
"fmt"
"math"
"os"
)
func main() {
fmt.Println("WELCOME TO GOLANG BMI CONVERTER")
for {
fmt.Println("choose 1 option")
fmt.Print("[1] Calculate BMI in Metric", "\n", "[2] Calculate BMI in Standard", "\n", "[3] Exit Program", "\n")
var value int
fmt.Scan(&value)
if value == 1 {
var cm, kg float64
fmt.Print("enter height(cm): ")
fmt.Scan(&cm)
fmt.Print("enter weight(kg): ")
fmt.Scan(&kg)
bmi_metric := metric_converter(cm, kg)
category := message(bmi_metric)
fmt.Printf("Your BMI is %v, %v", bmi_metric, category)
} else if value == 2 {
var foot, inches, pounds float64
fmt.Print("enter height(foot): ")
fmt.Scan(&foot)
fmt.Print("enter height(inches): ")
fmt.Scan(&inches)
fmt.Print("enter weight(lbs): ")
fmt.Scan(£s)
bmi_standard := standard_converter(foot, inches, pounds)
category := message(bmi_standard)
fmt.Printf("Your BMI is %.1f, %v\n", bmi_standard, category)
} else if value == 3 {
os.Exit(1)
} else {
fmt.Println("invalid character")
}
}
}
func metric_converter(height float64, weight float64) float64 {
num := float64((weight / height / height) * 10000)
return math.Round(num*10) / 10
}
func standard_converter(foot float64, inches float64, weight float64) float64 {
//converting foot to inches
height := (foot * 12) + inches
return math.Round(float64((weight/(height*height))*703)*10) / 10
}
func message(input float64) string {
switch {
case input < 18.5:
return "Underweight"
case 18.5 < input && input < 24.9:
return "Normal weight"
case 25 < input && input < 29.9:
return "Overweight"
case input > 30:
return "Obesity"
default:
return "failed"
}
}