#include<iostream>
#include<cmath>
using namespace std;

void getChoice(int& choice);
void getInput1(double& foot, double& inche);
void getInput2(double& meter, double& cm);
void convert1(double foot, double inche, double& meter, double& cm);
void convert2(double& foot, double& inche, double meter, double cm);
void showResult1(double foot, double inche, double meter, double cm);
void showResult2(double foot, double inche, double meter, double cm);

int main(){
    double feet, inches, meters, cms;
    int choices;

    do{
        getChoice(choices);

        if(choices == 1){
        getInput1(feet,inches);
        convert1(feet,inches,meters,cms);
        showResult1(feet,inches,meters,cms);
    }
    else if(choices == 2){
        getInput2(meters,cms);
        convert2(feet,inches,meters,cms);
        showResult2(feet,inches,meters,cms);

    }
    else if(choices == 0){
        return 0;
    }
    else{
        cout<<"Enter only interger(1/2)!"<<endl;
        getChoice(choices);
    }
    }while(choices != 0);
    return 0;
}

void getChoice(int& choice){
        cout<<"Select one of the following: "<<endl;
        cout<<"1. Convert feet and inches to meters and centimeters. \n";
        cout<<"2. Convert meters and centimeters to feet and inches. \n";
        cout<<"0. Quit.\n";
        cin>>choice;
}

void getInput1(double& foot, double& inche){
    cout<<"Enter feet and inches: ";
    cin>>foot>>inche;
}

void getInput2(double& meter, double& cm){
    cout<<"Enter meters and centimeter: ";
    cin>>meter>>cm;
}

void convert1(double foot, double inche, double& meter, double& cm){
    cm = ((foot*12)+inche) * 2.54;
    meter = cm / 100;

    double num = meter;
    double mPart1, mPart2;
    mPart2 = modf(num, &mPart1);
    meter = mPart1;
    cm = mPart2;
    cout<<meter<<endl;
    cout<<cm<<endl;
}

void convert2(double& foot, double& inche, double meter, double cm){
    cm += meter*100;
    cout<<cm<<endl;
    foot = ((cm/2.5))/12;

    double num = foot;
    double p1, p2;
    p2 = modf(num,&p1);
    foot = p1;
    inche = ceil(p2*10);
    cout<<foot<<" "<<inche<<endl;
}

void showResult1(double foot, double inche, double meter, double cm){
    cout<<foot<<" feet "<<inche<<" inches "<<"= "<<meter<<" meter "<<cm*100<<" centimeter."
        <<endl;
}

void showResult2(double foot, double inche, double meter, double cm){
    cout<<meter<<" meters "<<cm<<" centimeter "<<"= "<<foot<<" foots "<<inche<<" inches."
        <<endl;
}

Can anyone check this code for me?? The formula was like..abit weird..any thing that i can improve? Thanks for advance~

Does it work?

Does it work?

Yah..I just need some suggestion so that i can improve it or maybe i done something wrong in this program.. =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.