#include "pch.h"
#include <iostream>
using namespace std;
void showChoices();
void feetAndInchesToMetersAndCent(double feet, double inches, double &meters, double ¢);
void metersAndCentTofeetAndInches(double meters, double cent, double &feet, double &inches);
int main()
{
double v1, v2; // source data
double r1, r2; // result
short int choice;
for (;;) {
showChoices(); // show information
cout << '\n';
cin >> choice; // 1,2 or -1
cout << '\n';
if (choice == -1) break; // exit
else if (choice == 1) {
cout << "Meters and centimeters to feet and inches\n";
cout << "Enter first value: ";
cin >> v1;
cout << "Enter second value: ";
cin >> v2;
metersAndCentTofeetAndInches(v1,v2,r1,r2); // converting meters and centimeters to feet and inches
cout << v1 << " meters and " << v2 << " cents = " << r1 << " feet and " << r2 << " inches\n\n";
}
else if (choice == 2) {
cout << "feet and inches to meters and centimeters\n";
cout << "Enter first value: ";
cin >> v1;
cout << "Enter second value: ";
cin >> v2;
feetAndInchesToMetersAndCent(v1,v2,r1,r2); // converting feet and inches to meters and centimeters
cout << v1 << " feet and " << v2 << " inches = " << r1 << " meters and " << r2 << " cents\n\n";
}
else cout << "Unknown value, try again\n";
}
return 0;
}
void showChoices() { // show information
cout << "1 - meters and centimeters to feet and inches\n";
cout << "2 - feet and inches to meters and centimeters\n";
cout << "After selecting, enter 2 values(meters and centimeters, or feet and inches). -1 to exit\n";
}
void feetAndInchesToMetersAndCent(double feet, double inches, double &meters, double ¢) {
// 1 feet = 0.3048 meters
meters = feet * 0.3048;
// 1 inch = 2.54 cent
cent = inches * 2.54;
}
void metersAndCentTofeetAndInches(double meters, double cent, double &feet, double &inches) {
// 1 meter = 3.28084 feet
feet = meters * 3.28084;
//1 cent = 0.393701 inches
inches = cent * 0.393701;
}
Comments
Leave a comment