Something must be out of order, I think it is the if's or the classes but whenever I run this, the order messes up. If you click English ( choice 2) then the english way to find your BMI should show up, but instead the metric one shows up.
If I switch around Metric and English(making English first) then Metric uses the english way. Not sure how to fix this. Any help? Also, if there any ways to make this more effecient, that would help as well, thanks!
#include <iostream>
#include <string>
//BMI CALCULATOR
/*FORMULA
English BMI Formula
BMI = ( Weight in Pounds / ( Height in inches x Height in inches ) ) x 703
Metric BMI Formula
BMI = ( Weight in Kilograms / ( Height in Meters x Height in Meters ) )
*/
usingnamespace std;
class englishFormula {
public:
int englishBMI ()
{
unsignedshort age;
double inches, pounds;
string name;
cout << "Welcome to Hawk's BMI Calculator! Please follow the directions as shown.";
cout << "What is your name? ";
cin >> name;
cout << "Hello there " << name << "! Now, how old are you in years?\n" << endl;
cin >> age;
cout << "\nGreat, two more steps. What's your height in inches?\n";
cin >> inches; cout << "\nAnd your weight in pounds?" << endl;
cin >> pounds;
double english = (pounds/(inches * inches)) *703;
cout << "Your BMI is " << english;
}
};
class metricFormula {
public:
int metricBMI ()
{
unsignedshort age;
double kilos, meters;
string name;
cout << "Welcome to Hawk's BMI Calculator! Please follow the directions as shown.";
cout << "What is your name? ";
cin >> name;
cout << "Hello there " << name << "! Now, how old are you in years?\n" << endl;
cin >> age;
cout << "\nGreat, two more steps. What's your height in meters?\n";
cin >> meters; cout << "\nAnd your weight in kilograms?" << endl;
cin >> kilos;
double metric = (kilos/(meters* meters));
cout << "Your BMI is " << metric;
}
};
int main()
{
short choice;
cout << "Do you use Metric Units or English Units? " << endl;
cout << "\nMetric ~ Press 1";
cout << "\nEnglsih ~ Press 2\n" << endl;
cin >> choice;
switch(choice){
case 1:
cout << "You chose Metric. \n\n";
break;
case 2:
cout << "You chose English.\n" << endl;
break;
default:
cout << "Please choose one or two!";
}
if (1){
metricFormula metricObject;
metricObject.metricBMI();
}
elseif (2)
{
englishFormula englishObject;
englishObject.englishBMI();
}
return 0;
}