Conversion of feet/inches to meters-英尺、英里装换为米,允许重复计算:
//Conversion of feet/inches to meters-英尺、英里装换为米,允许重复计算
#include<iostream>
#include<cmath>
using namespace std;
void get_input(double& feet,double& inch);
double convert(double& feet,double& inch,double& meter);
void output(double meter);
int main()
{
double feet,inch,meter;
char ans;
do{
get_input(feet,inch);
convert(feet,inch,meter);
output(meter);
cout<<"Do you want again?";
cin>>ans;
}while('y' == ans || 'Y' == ans);
return 0;
}
void get_input(double& feet,double& inch)
{
cout<<"Enter the feet and the inch:\n";
cin>>feet>>inch;
}
double convert(double& feet,double& inch,double& meter)
{
double tem;
tem = feet + inch / 12;
meter = tem * 0.3048;
}
void output(double meter)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"The result is "<<meter<<"m"<<endl;
}
结果:
Enter the feet and the inch:
5 7
The result is 1.70m
Do you want again?y
Enter the feet and the inch:
245 0
The result is 74.68m
Do you want again?
转载于:https://blog.51cto.com/9320314/1547131