Advertisement
paulogp

BMI

Sep 5th, 2011
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. // xcode
  2. // paulogp
  3.  
  4. #include <stdio.h>
  5.  
  6. float bmi (float the_weight, float the_height);
  7.  
  8. float bmi (float the_weight, float the_height)
  9. {
  10.     // BMI = (Weight in Kilograms / (Height in Meters x Height in Meters))
  11.     float the_bmi = -1;
  12.  
  13.     if ((the_weight > 0) && (the_weight < 700) && (the_height > 0) && (the_height < 4.0))
  14.     {
  15.         the_bmi = the_weight / (the_height * the_height);
  16.     }
  17.  
  18.     return the_bmi;
  19. }
  20.  
  21. int main (int argc, const char * argv[])
  22. {
  23.     printf("BMI\n");
  24.  
  25.     float the_weight, the_height, the_result;
  26.  
  27.     printf("weight (kg): ");
  28.     scanf("%f", &the_weight);
  29.  
  30.     printf("height (m): ");
  31.     scanf("%f", &the_height);
  32.  
  33.     the_result = bmi (the_weight, the_height);
  34.  
  35.     if (the_result != -1)
  36.     {
  37.         if (the_result <= 18.5) printf("underweight\n");
  38.         if ((the_result > 18.5) && (the_result < 25)) printf("normal weight\n");
  39.         if ((the_result >= 25) && (the_result < 30)) printf("overweight\n");
  40.         if ((the_result >= 30) && (the_result < 35)) printf("obese 1\n");
  41.         if ((the_result >= 35) && (the_result < 40)) printf("obese 2\n");
  42.         if (the_result >= 40) printf("extremely obese\n");
  43.     }
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement