Advertisement
Guest User

bmi calc

a guest
Feb 7th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <string>
  2. #include <cmath>
  3. #include <iostream>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     cout << "Nate's \"Open Source\" BMI Calculator! \n\n";
  11.  
  12.     double myWeight;
  13.     double myHeight;
  14.     double row1;
  15.     double row2;
  16.     double row3;
  17.     double row4;
  18.  
  19.     cout << "Enter your height 'SPACE' and then weight and then hit 'ENTER'. \n";
  20.  
  21.     cin >> myHeight >> myWeight;
  22.  
  23.     double weight2 = myWeight * 0.45;
  24.     double height2 = myHeight * .025;
  25.     double height3 = height2 * height2;
  26.     double myBmi = weight2 / height3;
  27.  
  28.     cout << "Your BMI is " << myBmi << endl;
  29.    
  30.     ifstream bmiTable;
  31.     string tableLine1;
  32.     string tableLine2;
  33.     string tableLine3;
  34.     string tableLine4;
  35.  
  36.     bmiTable.open("bmi.txt");
  37.     bmiTable >> tableLine1 >> tableLine2 >> tableLine3 >> tableLine4;
  38.     cout << tableLine1 << " \n" << tableLine2 << " \n" << tableLine3 << " \n" << tableLine4 << " \n";
  39.    
  40.  
  41.  
  42.  
  43.    
  44.  
  45. //This is the block of code where I was going to do the extra credit and then got frustrated not knowing how to make a math equation in C++
  46. //where I compare bmi to be in between two possible values which I would assign to 18.5 and 24.9
  47. //
  48.  
  49.     if (myBmi < 18.5)
  50.         cout << "You are UNDERWEIGHT." << endl;
  51.    
  52.     else if (18.5 <= myBmi <= 24.9)
  53.         cout << "You are NORMAL." << endl;
  54.  
  55.     else if (24.9 <= myBmi <= 29.9)
  56.         cout << "You are OVERWEIGHT." << endl;
  57.  
  58.     else if (myBmi > 30.0)
  59.         cout << "You are OBESE." << endl;
  60.    
  61.    
  62.  
  63.  
  64.     cin.ignore(256, '\n');
  65.     cin.get();
  66.         return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement