Guest User

Untitled

a guest
Jul 21st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. //Lab 12 Question 2
  2. #include <iostream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int convertFeetToInches (int feet)
  8. {
  9. const int INCHES_PER_FOOT = 12;
  10. return (feet * INCHES_PER_FOOT);
  11. }
  12. double convertInchesToMeters (int inches)
  13. {
  14. const double METERS_PER_INCHES = 0.0254;
  15. return (inches * METERS_PER_INCHES);
  16. }
  17. double convertPoundsToKilos (int pounds)
  18. {
  19. const double KILOS_PER_POUND = 0.453592;
  20. return (pounds * KILOS_PER_POUND);
  21. }
  22. double calculateBMI(double weight, double height){
  23. return weight/(height*height);
  24. }
  25.  
  26. //Declaration of the main function
  27.  
  28. int main () {
  29. int feet, inches, inches_2, inches_3, pounds;
  30. double height, metres, weight, KG;
  31. double BMI;
  32. int mode = 0;
  33. int mode_2 = 0;
  34.  
  35. cout<<"*** Body Mass Index Program ***"<<endl;
  36. cout<<endl<<endl;
  37. cout<<"Height: (1) Feet and inches or (2) Metres: ";
  38. cin>>mode;
  39. cout<<endl<<endl;
  40.  
  41. if (mode == 1){
  42. cout<<" ";
  43. cout<<"Enter feet: ";
  44. cin>>feet;
  45. inches_2 = convertFeetToInches (feet);
  46. cout<<endl;
  47. cout<<" ";
  48. cout<<"Enter inches: ";
  49. cin>>inches_3;
  50. inches = inches_2+inches_3;
  51. cout<<endl;
  52. metres = convertInchesToMeters (inches);
  53. cout<<endl;
  54. }
  55. else {
  56. cout<<" ";
  57. cout<<"Enter Metres: ";
  58. cin>>metres;
  59. cout<<endl<<endl;
  60. }
  61.  
  62. height = metres;
  63.  
  64. cout<<"Weight: (1) Pounds or (2) Kilograms: ";
  65. cin>>mode_2;
  66. cout<<endl<<endl;
  67.  
  68. if (mode_2 == 1){
  69. cout<<" ";
  70. cout<<"Enter pounds: ";
  71. cin>>pounds;
  72. KG = convertPoundsToKilos (pounds);
  73. cout<<endl;
  74. }
  75. else {
  76. cout<<" ";
  77. cout<<"Enter Kilograms: ";
  78. cin>>KG;
  79. cout<<endl;
  80. }
  81. weight = KG;
  82. cout<<endl<<endl;
  83.  
  84. cout<<"The BMI is "<<calculateBMI(weight,height)<<"."<<endl;
  85.  
  86.  
  87. cout<<endl<<endl;
  88.  
  89. system ("PAUSE");
  90. return 0;
  91. }
Add Comment
Please, Sign In to add comment