首页 > 其他 > 详细

Conversion of feet/inches to meters-英尺、英里装换为米

时间:2014-08-31 18:46:44      阅读:718      评论:0      收藏:0      [点我收藏+]

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?


Conversion of feet/inches to meters-英尺、英里装换为米

原文:http://9320314.blog.51cto.com/9310314/1547131

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!