#include <iostream>
using namespace std;
// 编写一个程序,其main()调用一个用户定义的函数(以光年值为参数,并返回对应天文单位的值)。该程序按下面的格式要求用户输入光年值,并显示结果
//Enter the number of light years:4.2
//4.2 lights years =26608 astronomical units.
double lightToUnit(double); //声明调用函数原型
int main(){
double light,unit;//定义变量光年和天文单位
cout<<"Enter the number of light years: ";
cin>>light;
unit=lightToUnit(light);
cout<<light<<" lights years = "<<unit<<" astronomical units."<<endl;
return 0;
}
/**
光年转换为天文单位函数
*/
double lightToUnit(double light){
return light*63240;
}
C++Primer Plus (第6版)中文版 第2章 2.7 编程练习 第6题
最新推荐文章于 2018-05-03 09:50:48 发布