Metric to English conversion
Among the many measurement systems available, two seem to be the most widespread: metric and imperial. Imperial is "English measurements.
To make things simpler, we assume that the first one uses the "meter"as its only unit (expressed as a real number), while the second uses the "foot" (always an integer) and the "inch" (a real number).
Your task is to write a simple "measurement converter".
We want it to perform the following actions:
ask the user which system she/he uses to input data; we assume that 0 means "metric"and 1 means "imperial";
depending on the user's answer, ask either for meters or feet and inches;
output the distance in proper (different) units:either in feet and inches or in meters;
a result outputted as metric should look like 123.4m;
a result outputted as imperial should look like 12' 3.5".
For the conversion mathematical formulas, Click on the picture and check out this page
To make things simpler, we assume that the first one uses the "meter"as its only unit (expressed as a real number), while the second uses the "foot" (always an integer) and the "inch" (a real number).
Your task is to write a simple "measurement converter".
We want it to perform the following actions:
ask the user which system she/he uses to input data; we assume that 0 means "metric"and 1 means "imperial";
depending on the user's answer, ask either for meters or feet and inches;
output the distance in proper (different) units:either in feet and inches or in meters;
a result outputted as metric should look like 123.4m;
a result outputted as imperial should look like 12' 3.5".
For the conversion mathematical formulas, Click on the picture and check out this page
Some sample code to get you rolling
#include
using namespace std;
int main()
{
int sys;
float m, ft, in;
// Insert your code here
return 0;
}
using namespace std;
int main()
{
int sys;
float m, ft, in;
// Insert your code here
return 0;
}
A quick metric to imperial conversion video
To get Inches and feet from meters simply reverse the formula
Here are some samples to test your code with...
Example input
0
1
Example output
3' 3.37008"
Example input
1
3
3.37008
Example output
1m
Example input
0
0.0254
Example output
0' 1"
Example input
1
0
1
Example output
0.0254m
Example input
0
1
Example output
3' 3.37008"
Example input
1
3
3.37008
Example output
1m
Example input
0
0.0254
Example output
0' 1"
Example input
1
0
1
Example output
0.0254m