fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. // INPUT: 姓名, 身高, 體重
  7. string name;
  8. cin >> name; // take input and store to name
  9. cout << "Hello, " << name << "." << endl;
  10.  
  11. double height;
  12. cin >> height;
  13. height = height / 100;
  14.  
  15. double weight;
  16. cin >> weight;
  17.  
  18. // ALGORITHM
  19. double bmi = weight / height / height;
  20.  
  21. // OUTPUT
  22. cout << name << " (" << bmi << ")" << endl;
  23. if (bmi < 18.5) {
  24. cout << "體重過輕" << endl;
  25. } else if (bmi >= 24) {
  26. cout << "體重過重" << endl;
  27. } else {
  28. cout << "體重適中" << endl;
  29. }
  30.  
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5496KB
stdin
Arthur 173 75
stdout
Hello, Arthur.
Arthur (25.0593)
體重過重