题目:编写一个程序:要求用户输入小时数和分钟数。在main()函数中,将这两个值传递给一个void函数,后者以下面的格式显示这两个值:
Enter the number of hours:hh
Enter the number of minutes:mm
Time:hh:mm
程序:
//timeout.cpp---输入时间和分钟,输出完整时间格式。
#include<iostream>
usingnamespace std;
void timeOut(int,int);
int main()
{
int h;
int m;
cout<<"Enter the number of hours:"<<endl;
cin>>h;
cout<<"Enter the number of minutes:"<<endl;
cin>>m;
timeOut(h,m);
return 0;
}
void timeOut(int h,int m)
{
cout<<"Time:"<<h<<":"<<m<<endl;
}
关于int main():
int main(),main函数返回一个整数值。可以将计算机造作系统看作调用程序。因此,main()的返回值并不是返回给程序的其他部分,而是返回给操作系统。很多操作系统都可以使用程序的返回值。例如,UNIX外壳脚本和Windows命令批处理文件都被设计成运行程序,并测试它们的返回值(通常叫做退出值)。通常的约定是,退出值为0则意味着程序成功运行,为非零则意味着存在问题。因此,如果C++程序无法打开文件,可以将它设计为返回一个非零值。然后,便可以设计一个外壳脚本或批处理文件来运行该程序,如果该程序发出指示失败的消息,则采取其他措施。
环境:Code::Blocks
运行结果:


















