Converting Metric to English and Visa Versa

I realize the topic sounds extremely easy, but the trouble I'm having with the program is rounding. The program is supposed to ask the user for one measurement, either feet or meters. The program is then supposed to convert meters into feet, inches, and square inches, or convert feet into meters and centimeters. I'm unsure what equations to use to round the measurements into inches, square inches, and centimeters. The functions can be located at the bottom of the code (feetToMeters and metersToFeet).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

#include <iostream>


using namespace std;

void readInput(int &typeConv, int &feet, int &inches, int &qrtrInch, int &meters, int &centimeters );

void feetToMeters(int feet, int inch, int &meters, int &centimeters); 

void metersToFeet(int meters,int centimeters, int &feet, int &inches, int &qrtrInches);

void printResults(int typeConv,int feet,int inches,int qrtrinches,int meters, int centimeters );//


int const SENTINEL = 0;
int const METRIC_TO_ENGLISH = 1;
int const ENGLISH_TO_METRIC = 2;

int main(){
    //1.0 Variable Dictionary
    
    int typeConv; // Metric to English(1) or English to Metric(2)
    int feet;
    int inches;
    int qrtrInches;
    int meter;
    int centimeter;
   
  
    //2.0 Processing user input and performing desired conversion
    
    do {
    readInput(typeConv, feet, inches, qrtrInches, meter, centimeter); 
        
    
        
     //3.0 Outputting Results
        
    printResults(typeConv, feet, inches, qrtrInches, meter, centimeter);
    
    }
    
    
    while(typeConv != SENTINEL);
    
    cout<<"<<<<<<<<<< NORMAL PROGRAM TERMINATION >>>>>>>>>>"<<endl;
    
    
    return 0;
    
}

void feetToMeters(int feet, int inches, int &meters, int &centimeters){
    meters = feet * .3048;
    centimeters = inches * 1; 
    
}

void metersToFeet(int meters,int centimeters, int &feet, int &inches, int &qrtrInches){
    feet = meters / .3048;
    inches = 1; <--------
    qrtrInches = 1; <-------
    
  
}

void readInput(int &typeConv, int &feet, int &inches, int &qrtrInches, int &meters, int &centimeters ){
    cout<<"Do you wish to convert metric to english (Enter 1) or english to metric (Enter 2)?"<<endl;
    cin>>typeConv;
    
    if(typeConv == METRIC_TO_ENGLISH){
        cout<<"Enter how many meters."<<endl;
        cin>>meters;
        metersToFeet(meters,centimeters, feet, inches, qrtrInches);
    }
    else if(typeConv == ENGLISH_TO_METRIC) {
        cout<<"Enter how many feet."<<endl;
        cin>>feet;
        feetToMeters(feet, inches, meters, centimeters );
    }
  
    
}




void printResults(int typeConv,int feet,int inches,int qrtrInches,int meters, int centimeters ){
    if(typeConv == 1){
        cout<<"\n"<<meters<<" Meters is equal to " <<feet << " feet " << inches << " inches and " <<qrtrInches << " quarter inches"<<endl;
        cout<<"Type 0 to exit program\n";
        cout<<"\n" ;
        
    }
    
    if(typeConv == 2){
        cout<<"\n"<<feet<<" feet is equal to "<< meters << " meters and " << centimeters << " centimeters"<<endl;
        cout<<"Type 0 to exit program\n";
        cout<<"\n" ;
    }
    
}

Last edited on
You ask for integer feet. Therefore, there are no inches to care about.

Convert the feet to integer centimeters. Then use operators / and % to get meters and the remainder centimeters.

Same to the other direction: convert to smallest unit. Then extract the bigger ones, if any.
Topic archived. No new replies allowed.