-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_2.cpp
55 lines (46 loc) · 1.42 KB
/
3_2.cpp
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
#include <iostream>
#include <cmath>
using namespace std;
const int InchesPerFoot = 12;
const double MeterPerInch = 0.0254;
const double PoundsPerKilogram = 2.2;
double caculateBMI(int feet, int inches, int pounds);
int main()
{
int feet;
int inches;
int pounds;
cout << "Please enter your height: ____feet, ____inches\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
while(!(cin >> feet) || (0 > feet))
{
cout << "Error! Please enter a positive number: _____\b\b\b\b";
cin.clear();
cin.sync();
}
cout << "Please enter your height: " << feet << " feet, ____inches\b\b\b\b\b\b\b\b\b\b";
while(!(cin >> inches) || (0 > inches) || (0 == feet && 0 == inches))
{
cout << "Error! Please enter a positive number: _____\b\b\b\b";
cin.clear();
cin.sync();
}
cout << "Please enter your weight: ____pounds\b\b\b\b\b\b\b\b\b\b";
while(!(cin >> pounds) || (0 > pounds))
{
cout << "Error! Please enter a positive number: _____\b\b\b\b";
cin.clear();
cin.sync();
}
double BMI = caculateBMI(feet, inches, pounds);
cout << "Your BMI is " << BMI << endl;
// system("pause");
return 0;
}
double caculateBMI(int feet, int inches, int pounds)
{
double height = (feet * InchesPerFoot + inches) * MeterPerInch;
// cout << "Your height is " << height << endl;
double weight = pounds / PoundsPerKilogram;
// cout << "Your weight is " << weight << endl;
return weight/ pow(height, 2);
}