i am trying to write a program that converts a height that is given by user input to a scale that is also chosen by user input.
first the program is supposed to ask the user which scale they'd like to convert to, metric or imperial.
then based on that choice it's supposed to ask the user for the height they want to convert.
my problem is that my control statements don't seem to be working. when i type "imperial" to indicate that i want to convert from metric units to imperial units, i get asked to enter the height in imperial units when it should be asking me to do it in metric units, and then it prints the metric height when it should be returning the imperial height.
any advice on how i can fix this? thank you in advance.
#include <iostream>
using namespace std;
void getImperialData(double& big, double& small);
void getMetricData(double& big, double& small);
void toMetric(double& big, double& small);
void toImperial(double& big, double& small);
void giveMetricHeight(double meters, double centimeters);
void giveImperialHeight(double feet, double inches);
int main() {
double big, small;
char ans;
cout << endl << endl;
do{
string units;
cout << "Convert to which units? (metric/imperial): ";
cin >> units;
cout << endl << endl;
if (units == "metric" || "Metric"){
getImperialData(big, small);
cout << endl << endl;
toMetric(big, small);
cout << endl << endl;
giveMetricHeight(big, small);
cout << endl << endl;
} if (units == "imperial" || units == "Imperial"){
getMetricData(big, small);
cout << endl << endl;
toImperial(big, small);
cout << endl << endl;
giveImperialHeight(big, small);
cout << endl << endl;
} else {
cout << "Please choose imperial or metric units.";
cout << endl << endl;
}
cout << "Convert another height? (y/n): ";
cin >> ans;
cout << endl;
}while(ans == 'y' || ans == 'Y');
return 0;
}
void getImperialData(double& big, double& small){
cout << "Enter the number of feet: ";
cin >> big;
cout << endl << endl;
cout << "Enter the number of inches: ";
cin >> small;
cout << endl << endl;
}
void getMetricData(double& big, double& small){
cout << "Enter the number of meters: ";
cin >> big;
cout << endl << endl;
cout << "Enter the number of centimeters: ";
cin >> small;
cout << endl << endl;
}
void toMetric(double& big, double& small){
big = 0.3048 * big;
small = 2.54 * small;
}
void toImperial(double& big, double& small){
big = big / 0.3048;
small = small / 2.54;
}
void giveMetricHeight(double meters, double centimeters){
cout << "This height is " << meters + centimeters << " meters." << endl << endl;
}
void giveImperialHeight(double feet, double inches){
cout << "This height is " << feet << " feet " << " and " << inches << " inches." << endl << endl;
}