cpp_primer_plus/ch03/02.cpp

27 lines
594 B
C++
Raw Normal View History

2022-08-24 05:44:15 +08:00
# include <iostream>
# include <cmath>
using namespace std;
int ic2ft = 12; // 1 inch = 12 feet
double ft2m = 0.0254; // 1 feet = 0.0254 meter
float kg2p = 2.2;
double bmi (double a, double b);
int main(){
double inch, feet;
double pound;
cout << "Enter Your Height (Inch feet): ";
cin >> inch >> feet;
double meter = (inch * ic2ft + feet) * ft2m;
cout << "Enter Your Weight (pound): ";
cin >> pound;
double kg = pound / kg2p;
double c = bmi (kg, meter);
cout << "The BIM is " << c << endl;
return 0;
}
double bmi (double a, double b){
double c = 1 / pow(b,2) * a;
return c;
}