Length Conversion Program

Write a program that will read in a length in feet and inches and will output the equivalent length in meters and centimeter. Use at least three functions: one for input, one or more for calculating, and one for output. Include a loop that lets the user repeat this computation for new input values until the user says he wants to end the program. There are meter in a foot, 100 centimeters in a meter, and 12 inches in a foot.

Questions by DM27dexter

Showing Answers 1 - 1 of 1 Answers

#include "iostream"

using namespace std;

struct metric{
int meters;
int centimeters;
};

struct english{
int feet;
int inches;
};

void input( english &value ) {
std::cout << "Type zeroes to exit:n";
std::cout << "Give me the feet: ";
std::cin >> value.feet;
std::cout << "Give me the inches: ";
std::cin >> value.inches;
while ( value.inches > 11 ) {
value.feet += 1;
value.inches -= 12;
}
std::cout << "Feet: " << value.feet << "ninches: " << value.inches << std::endl;
}

void output( metric &value ) {
std::cout << "Meters: " << value.meters << "ncentimiters: " << value.centimeters << std::endl;
}

void convert_to_metric( english &value1, metric &value2){
// convert all to inches and multiply by 2.58 to get centimeters
value2.centimeters = (int)(((value1.feet * 12) + value1.inches ) * 2.58);
while ( value2.centimeters > 99 ){
value2.meters += 1;
value2.centimeters -= 100;
}
}

int main( void ) {
english e_value = {0};
metric  m_value = {0};
do {
input(e_value);
convert_to_metric(e_value, m_value);
output(m_value);
m_value.meters    = 0;
m_value.centimeters = 0;
}
while ( e_value.feet != 0 && e_value.inches != 0 );
return 0;
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions