Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lab 12 Question 2
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int convertFeetToInches (int feet)
- {
- const int INCHES_PER_FOOT = 12;
- return (feet * INCHES_PER_FOOT);
- }
- double convertInchesToMeters (int inches)
- {
- const double METERS_PER_INCHES = 0.0254;
- return (inches * METERS_PER_INCHES);
- }
- double convertPoundsToKilos (int pounds)
- {
- const double KILOS_PER_POUND = 0.453592;
- return (pounds * KILOS_PER_POUND);
- }
- double calculateBMI(double weight, double height){
- return weight/(height*height);
- }
- //Declaration of the main function
- int main () {
- int feet, inches, inches_2, inches_3, pounds;
- double height, metres, weight, KG;
- double BMI;
- int mode = 0;
- int mode_2 = 0;
- cout<<"*** Body Mass Index Program ***"<<endl;
- cout<<endl<<endl;
- cout<<"Height: (1) Feet and inches or (2) Metres: ";
- cin>>mode;
- cout<<endl<<endl;
- if (mode == 1){
- cout<<" ";
- cout<<"Enter feet: ";
- cin>>feet;
- inches_2 = convertFeetToInches (feet);
- cout<<endl;
- cout<<" ";
- cout<<"Enter inches: ";
- cin>>inches_3;
- inches = inches_2+inches_3;
- cout<<endl;
- metres = convertInchesToMeters (inches);
- cout<<endl;
- }
- else {
- cout<<" ";
- cout<<"Enter Metres: ";
- cin>>metres;
- cout<<endl<<endl;
- }
- height = metres;
- cout<<"Weight: (1) Pounds or (2) Kilograms: ";
- cin>>mode_2;
- cout<<endl<<endl;
- if (mode_2 == 1){
- cout<<" ";
- cout<<"Enter pounds: ";
- cin>>pounds;
- KG = convertPoundsToKilos (pounds);
- cout<<endl;
- }
- else {
- cout<<" ";
- cout<<"Enter Kilograms: ";
- cin>>KG;
- cout<<endl;
- }
- weight = KG;
- cout<<endl<<endl;
- cout<<"The BMI is "<<calculateBMI(weight,height)<<"."<<endl;
- cout<<endl<<endl;
- system ("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment