fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. double height_cm, weight;
  7.  
  8. cout << "Enter your height (cm): ";
  9. cin >> height_cm;
  10. cout << "Enter your weight (kg): ";
  11. cin >> weight;
  12.  
  13. // Convert height from cm to meters
  14. double height_m = height_cm / 100.0;
  15. double bmi = weight / (height_m * height_m);
  16.  
  17. string category;
  18.  
  19. if (bmi < 18.5) {
  20. category = "Underweight";
  21. } else if (bmi < 24) {
  22. category = "Normal Weight";
  23. } else if (bmi < 27) {
  24. category = "Overweight";
  25. } else if (bmi < 30) {
  26. category = "Mildly Obese";
  27. } else if (bmi < 35) {
  28. category = "Moderately Obese";
  29. } else {
  30. category = "Severely Obese";
  31. }
  32.  
  33. cout << "Your BMI is " << bmi << " (" << category << ")" << endl;
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5280KB
stdin
166
48
stdout
Enter your height (cm): Enter your weight (kg): Your BMI is 17.4191 (Underweight)