1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <iostream>
#include <cmath>
float bmi(float, float); //prototype
float bmi_inpound(float, float); //prototype
int main (int argc, char * const argv[]) {
float height_cm, weight_kg, height_inch, weight_pound, ur_bmi, ur_bmi_inpound;
char height_unit = 'a', weight_unit = 'a';
std::cout << "Welcome to the BMI Centre.\n";
do {
std::cout << "Please select the unit of your height:\n";
std::cout << "Press I for inch. Press C for centimeter.\n";
std::cin >> height_unit;
if (height_unit=='I') {
std::cout << "Please enter your height:\n";
std::cin >> height_inch;
}
else if(height_unit=='C') {
std::cout << "Please enter your height:\n";
std::cin >> height_cm;
}
} while (height_unit != 'I'||height_unit != 'C');
do {
std::cout << "Please select the unit of your weight:\n";
std::cout << "Press P for pound. Press K for kilogram.\n";
std::cin >> weight_unit;
if (weight_unit=='P') {
std::cout << "Please enter your weight:\n";
std::cin >> weight_pound;
}
else if(weight_unit=='C'); {
std::cout << "Please enter your weight:\n";
std::cin >> weight_kg;
}
} while (weight_unit!='P'||weight_unit!='K');
if (height_unit=='I') {
ur_bmi_inpound = bmi_inpound(weight_pound, height_inch);
std::cout << "Your BMI is " << ur_bmi_inpound << ".\n";
std::cout << "Thank you.\n";
}
else if(height_unit=='C') {
ur_bmi = bmi(weight_kg, height_cm);
std::cout << "Your BMI is " << ur_bmi << ".\n";
std::cout << "Thank you.\n";
}
return 0;
}
float bmi_inpound (float w, float h) {
float final_bmi;
final_bmi = w * 704.5 * h / h;
return final_bmi;
}
float bmi (float w, float h) {
float final_bmi;
final_bmi = w /pow(h,2.0);
return final_bmi;
}
| |