请教一道题目的答案!

wj1631 2010-03-31 07:49:37
我是个新手在学C++,课后有个题目不知道怎么做,请各位帮忙解答下。

编写一个程序,要求用户输入小时数和分钟数,在main()函数中,将这两个值传递给一个void函数,后者以下面这样的格式显示这2个值;
Enter the number of hours: 9
Enter the number of minutes: 28
Time: 9:28



我不知怎么去定义一个void的函数显示以上的内容!!各位帮忙解答下,感激不尽啊!!
...全文
117 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wj1631 2010-03-31
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 yuzl32 的回复:]
C/C++ code

#include <iostream>

using namespace std;

void show(int h,int m)
{
cout < < "Time:" < < h < < ":" < < m ;
}

int main()
{
int h,m;
cout < < "Enter the number of hou……
[/Quote]

谢谢了 问个问题,这个自定义函数必须得放到main函数之前么????

怪不得我编译不过,我都放后面去了
yuzl32 2010-03-31
  • 打赏
  • 举报
回复

#include <iostream>

using namespace std;

void show(int h,int m)
{
cout << "Time:"<< h << ":" << m ;
}

int main()
{
int h,m;
cout << "Enter the number of hours:";
cin >> h;
cout << "Enter the number of minutes:";
cin >> m;

show(h,m);
}
yuzl32 2010-03-31
  • 打赏
  • 举报
回复

#include <iostream>

using namespace std;

int main()
{
int h,m;
cout << "Enter the number of hours:";
cin >> h;
cout << "Enter the number of minutes:";
cin >> m;

cout << "Time:"<< h << ":" << m ;
}
wj1631 2010-03-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 qdj6679 的回复:]
可以定义两个变量啊,不一定只要一个变量就可以了
[/Quote]

能帮忙把代码写出来么
qdj6679 2010-03-31
  • 打赏
  • 举报
回复
可以定义两个变量啊,不一定只要一个变量就可以了

33,317

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧