# Thread: Unit conversion with 3 functions

1. ## Unit conversion with 3 functions

Hello I am a very new to C++. I am trying to convert a given number of meters and centimeters into feet and inches using three function. I think that I am close but since i am new I am having a hard time figuring out what i have done wrong. Thanks,

Code:
```#include <iostream>
using namespace std;

double unitconversion (double lengthme, double lengthcent);
void unitoutput (double lengthme, double lengthcent);

int main ()
{
double lengthme, lengthcent;

do
{
cout<<"Enter a length in meters and centimeters to be converted:";
cin>>lengthme>>lengthcent;
cout<<unitoutput (lengthme, lengthcent);
cout<<"\n Test again (y/n)";
cout<<endl;

system ("PAUSE");
return 0;
}

double unitconversion (double lengthme, double lengthcent)
{
lengthme=lengthme/0.3048;
lengthcent=lengthcent/100;
lengthcent=lengthcent/0.3048;
lengthcent=lengthcent*12;
return (lengthme, lengthcent);
}
void unitoutput (double lengthme, double lenghtcent)
{
cout<<"The length is "<<lengthme<<" ft and "<<lengthcent<<" in.\n";
}```

2. Errors:
1. You haven't called the unitconversion function.
2. A function can return only one value at time, you might pass the parameters as a reference.
3. don't cout<<unitoutput(lengthme, lengthcent);
just call unitoutput(lengthme, lengthcent);

Suggestions
1. You are converting the metres to feet and centimetres to inches which is not exactly helpful. You should reconsider the unitconversion function.
2. while (answer== 'y' || answer== 'y') both 'y's are in lowercase hence redundant.

3. Ya I know the conversion isn't very helpful. This is for a school project and it specifically asks for this conversion. Weird I know. I made the change but it is still not compiling correctly
Code:
```#include <iostream>
using namespace std;

void unitconversion (double lengthme, double lengthcent);
void unitoutput (double lengthme, double lengthcent);

int main ()
{
double lengthme, lengthcent;

do
{
cout<<"Enter a length in meters and centimeters to be converted:";
cin>>lengthme>>lengthcent;
unitconversion (lengthme, lengthcent);
unitoutput (lengthme, lengthcent);
cout<<"\n Test again (y/n)";
cout<<endl;

system ("PAUSE");
return 0;
}

void unitconversion (double lengthme, double lengthcent)
{
lengthme=lengthme/0.3048;
lengthcent=lengthcent/100;
lengthcent=lengthcent/0.3048;
lengthcent=lengthcent*12;
}
void unitoutput (double lengthme, double lengthcent)
{
cout<<"The length is "<<lengthme<<" ft and "<<lengthcent<<" in.\n";
}```

4. pass the parameters as a refrence.
void unitconversion (double &lengthme, double &lengthcent);
remove the return statement in unitconversion
don't cout<<unitoutput(lengthme, lengthcent);
just call unitoutput(lengthme, lengthcent)

5. Awesome!! Doing the '&' in front of the variables actually did the trick. Thank you for your help, I have been surprised in the subtle differences between c and c++; I really apreciate the help.