# Unit conversion with 3 functions

• 02-08-2013
Magi
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;     char answer;         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)";         cin>>answer;         cout<<endl;         }while (answer== 'y' || answer== 'y');             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";       }```
• 02-08-2013
Chanakya
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.
• 02-08-2013
Magi
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;     char answer;         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)";         cin>>answer;         cout<<endl;         }while (answer== 'y' || answer== 'y');               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";       }```
• 02-08-2013
Chanakya
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)
• 02-08-2013
Magi
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.