I'm supposed to make a code that converts from feet and inches to meters and centimeters. But when I run my code, I don't get what I should get. For example, I input 1 foot and 0 centimeters. I should get 0.3048 meters and 0 centimeters but instead I'm getting 1 meters and 0 centimeters . Help!
#include <iostream>
using namespace std;
void getLength(double& input1, double& input2);
void convert(double& variable1, double& variable2);
void showLengths(double output1, double output2);
int main()
{
double feet, inches;
char ans;
do
{
getLength(feet, inches);
convert(feet, inches);
showLengths(feet, inches);
cout << "Would you like to go again? (y/n)" << endl;
cin >> ans;
cout << endl;
} while (ans == 'y' || ans == 'Y');
}
void getLength(double& input1, double& input2)
{
cout << "What are the lengths in feet and inches? " << endl;
cin >> input1 >> input2;
cout << input1 << " feet and " << input2 << " inches is converted to ";
}
void convert (double& variable1, double& variable2)
{
double meters = 0.3048, centimeters = 2.54;
meters *= variable1;
centimeters *= variable2;
}
void showLengths (double output1, double output2)
{
cout << output1 << " meter(s) and " << output2 << " centimeter(s)" << endl;
}
Any help is appreciated. Thanks!
meters *= variable1is equivalent tometers = meters * variable1, i.e. you assign the result of the multiplication tometers.