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 ¢imeters );
void feetToMeters(int feet, int inch, int &meters, int ¢imeters);
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 ¢imeters){
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 ¢imeters ){
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" ;
}
}
|