标签:
习题答案:2.7
5.
#include <iostream>
using namespace std;
void Fah();
int main()
{
Fah();
return 0;
}
void Fah()
{
int Celsius;
cout<<"Please enter a Celsius value:";
cin>>Celsius;
double Fahrenheit;
Fahrenheit=1.8*Celsius+32.0;
cout<<Celsius<<"degrees Celsius is"<<Fahrenheit<<"degrees Fahrenheit."<<endl;
int i;
cin>>i;
}
错误原因:没有在头文件中写申明//void Fah();
运行结果:
6.#include <iostream>
using namespace std;
void change();
int main()
{
change();
int i;
cin>>i;
return 0;
}
void change()
{
double light;
cout<<"Please enter the number of light years:";
cin>>light;
double ast;
ast=63240*light;
cout<<light<<"light years"<<ast<<"astronomical units."<<endl;
}
运行结果
7.#include <iostream>
using namespace std;
void see(int hours,int minutes);//里面的参数将决定主函数中调用参数的个数
int main()
{
cout<<"Enter the number of hours:";
int hours;
cin>>hours;
cout<<"Enter the number of minutes:";
int minutes;
cin>>minutes;
see(hours,minutes);
int i;
cin>>i;
return 0;
}
void see(int hours,int minutes)
{
cout<<"Time:"<<hours<<":"<<minutes;
}
标签:
原文地址:http://www.cnblogs.com/FFDC3EM/p/4790054.html