#include #include #include bool classify_person(void); bool is_mass_valid(double mass); /** @brief Returns true if is a valid height for a human being @details @code if ... @endcode @param height A real number in centimeters @return True if height is suitable for a human being */ bool is_height_valid(double height); /** @param bmi Must be always positive */ const char* classify_body_mass_index(double bmi); // procedure Main: int main(void) { // While there is data then while (classify_person()) { // Classify person } } #include // procedure Classify person: bool classify_person(void) { // Read mass in kilograms double mass = 0.0; // Read height in centimeters double height_in_cm = 0.0; if (scanf("%lg %lg", &mass, &height_in_cm) == 2) { // Print mass, height printf("%6.2lf %6.2lf ", mass, height_in_cm); // If is mass valid and is height in centimeters valid then if (is_mass_valid(mass) && is_height_valid(height_in_cm)) { // Create height in meters as height in centimeters / 100 const double height_in_meters = height_in_cm / 100.0; // Create body mass index as mass / height in meters^2 const double bmi = mass / (height_in_meters * height_in_meters); // Create nutrition state as the result of classifying the body mass index const char* const nutrition_state = classify_body_mass_index(bmi); // Print body mass index, nutrition state printf("%5.2lf %s\n", bmi, nutrition_state); } else { // Print "invalid data" printf("invalid data\n"); } // Continue reading the next person return true; } else { // Stop, there is no more people return false; } } // function is mass valid: bool is_mass_valid(double mass) { // Return mass > 0 and mass <= 1000 return mass > 0 && mass <= 1000; } // function is height valid: bool is_height_valid(double height) { // return height > 0 and height <= 300 return height > 0 && height <= 300; } // function classify the body mass (bmi) index: const char* classify_body_mass_index(double bmi) { // if bmi < 18.5 then if (bmi < 18.5) { return "underweight"; } // if bmi < 25 then if (bmi < 25) { return "normal"; } // if bmi < 30 then if (bmi < 30) { return "overweight"; } return "obese"; }