Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // xcode
- // paulogp
- #include <stdio.h>
- float bmi (float the_weight, float the_height);
- float bmi (float the_weight, float the_height)
- {
- // BMI = (Weight in Kilograms / (Height in Meters x Height in Meters))
- float the_bmi = -1;
- if ((the_weight > 0) && (the_weight < 700) && (the_height > 0) && (the_height < 4.0))
- {
- the_bmi = the_weight / (the_height * the_height);
- }
- return the_bmi;
- }
- int main (int argc, const char * argv[])
- {
- printf("BMI\n");
- float the_weight, the_height, the_result;
- printf("weight (kg): ");
- scanf("%f", &the_weight);
- printf("height (m): ");
- scanf("%f", &the_height);
- the_result = bmi (the_weight, the_height);
- if (the_result != -1)
- {
- if (the_result <= 18.5) printf("underweight\n");
- if ((the_result > 18.5) && (the_result < 25)) printf("normal weight\n");
- if ((the_result >= 25) && (the_result < 30)) printf("overweight\n");
- if ((the_result >= 30) && (the_result < 35)) printf("obese 1\n");
- if ((the_result >= 35) && (the_result < 40)) printf("obese 2\n");
- if (the_result >= 40) printf("extremely obese\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement