fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void rateLevelOfObesityBasedOnBmi (float bmi, string forename, vector <string>& peopleWithUnderweight,
  7. vector <string>& peopleWithCorrectWeight,
  8. vector <string>& peopleWtihOverweight);
  9. void showObesityClassificationsOfPeople (vector <string>& peopleWithUnderweight,
  10. vector <string>& peopleWithCorrectWeight,
  11. vector <string>& peopleWtihOverweight);
  12.  
  13. int main()
  14. {
  15. int numberOfPeople;
  16. cin >> numberOfPeople;
  17. string forename;
  18. float weight, height;
  19.  
  20. vector <string> peopleWithUnderweight;
  21. vector <string> peopleWithCorrectWeight;
  22. vector <string> peopleWtihOverweight;
  23.  
  24. for(int i = 0; i < numberOfPeople; i++)
  25. {
  26. cin >> forename;
  27. do
  28. cin >> weight;
  29. while (weight <= 0);
  30. do
  31. cin >> height;
  32. while (height <= 0);
  33.  
  34. float bmi = (weight / ((height / 100.) * (height / 100.)));
  35. rateLevelOfObesityBasedOnBmi (bmi, forename, peopleWithUnderweight, peopleWithCorrectWeight, peopleWtihOverweight);
  36. }
  37. if (numberOfPeople == 0)
  38. return 0;
  39. showObesityClassificationsOfPeople (peopleWithUnderweight, peopleWithCorrectWeight, peopleWtihOverweight);
  40.  
  41. return 0;
  42. }
  43.  
  44. void rateLevelOfObesityBasedOnBmi (float bmi, string forename, vector <string>& peopleWithUnderweight,
  45. vector <string>& peopleWithCorrectWeight,
  46. vector <string>& peopleWtihOverweight)
  47. {
  48. if (bmi < 18.5)
  49. peopleWithUnderweight.push_back(forename);
  50. else if ((bmi >= 18.5) && (bmi < 25))
  51. peopleWithCorrectWeight.push_back(forename);
  52. else if (bmi >= 25)
  53. peopleWtihOverweight.push_back(forename);
  54. }
  55.  
  56. void showObesityClassificationsOfPeople (vector <string>& peopleWithUnderweight,
  57. vector <string>& peopleWithCorrectWeight,
  58. vector <string>& peopleWtihOverweight)
  59. {
  60. cout << "niedowaga" << endl;
  61. for(int i = 0; i < peopleWithUnderweight.size(); i++)
  62. cout << peopleWithUnderweight[i] << endl;
  63.  
  64. cout << '\n';
  65. cout << "waga prawidlowa" << endl;
  66. for(int i = 0; i < peopleWithCorrectWeight.size(); i++)
  67. cout << peopleWithCorrectWeight[i] << endl;
  68.  
  69. cout << '\n';
  70. cout << "nadwaga" << endl;
  71. for(int i = 0; i < peopleWtihOverweight.size(); i++)
  72. cout << peopleWtihOverweight[i] << endl;
  73. }
  74.  
Success #stdin #stdout 0s 4140KB
stdin
Standard input is empty
stdout
Standard output is empty