Write a program that reads in a length in feet and inches and outputs the equivalent length in meters and centimeters. 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 or she wants to end the program. There are 0.3048 meters in a foot, 100 centimeters in a meter, and 12 inches in a foot.
Program:
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
void inputData(float &feet,float &inches);
void calcFeetInches(float feet,float inches,float &meters,
float &cm);
void output(float meters,float cm,float feet,float inches);
int main()
{
float feet, inches, meters, cm;
char answer;
do
{
cout << " Feet and inches to meters and centimeters"
<< endl;
inputData(feet,inches);
calcFeetInches(feet,inches,meters,cm);
output(meters,cm,feet,inches);
cout<<"To repeat calculation enter 'y' or 'Y'"<<endl;
cin>>answer;
} while (answer == 'y'||answer=='Y');
return 0;
}
void inputData(float &feet,float &inches)
{
cout << "Feet: ";
cin >> feet;
cout << "Inches: ";
cin >> inches;
}
void calcFeetInches(float feet,float inches,
float &meters,float &cm)
{
meters = feet* 0.3048 + (inches*0.0254);
cm=(feet*30.48+inches*2.54);
}
Output:
Feet and inches to meters and centimeters
Feet: 100
Inches: 11
There are 30.7594 meters, 3075.94 centimeters in 100 feet, 11 inches
To repeat calculation enter 'y' or 'Y':n