-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmi.c
63 lines (50 loc) · 1.44 KB
/
bmi.c
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
#include <stdio.h>
#include "bmi.h"
void calculate_bmi_imperial() {
UserInfo user_info;
float ft, in;
printf("---\n");
printf("Enter your weight (lbs): ");
scanf(" %f", &user_info.weight);
printf("Enter your height:\n");
printf(" Feet: ");
scanf(" %f", &ft);
printf(" Inches: ");
scanf(" %f", &in);
user_info.height = convert_ft_to_in(ft, in);
// calculate BMI
user_info.bmi = 703 * (user_info.weight / (user_info. height * user_info.height));
printf("\n");
print_result(user_info.bmi);
}
void calculate_bmi_metric() {
UserInfo user_info;
printf("---\n");
printf("Enter your weight (kg): ");
scanf(" %f", &user_info.weight);
printf("Enter your height (m): ");
scanf(" %f", &user_info.height);
// calculate BMI
user_info.bmi = user_info.weight / (user_info.height * user_info.height);
print_result(user_info.bmi);
}
char * get_bmi_status(float bmi) {
char *status;
if(bmi < 18.5)
status = "UNDERWEIGHT";
else if (bmi >= 18.5 && bmi <= 24.9)
status = "HEALTHY";
else if (bmi > 24.9 && bmi < 29.9)
status = "OVERWEIGHT";
else if (bmi > 30.0)
status = "OBESITY";
return status;
}
float convert_ft_to_in(float ft, float in) {
return (ft * 12) + in;
}
void print_result(float bmi) {
printf("\n");
printf("Your BMI is %.2f\n", bmi);
printf("Your are in \"%s\" range\n", get_bmi_status(bmi));
}