注册 登录
编程论坛 C++教室

两个值传递给一个void函数的问题,请同志们给看一下

只手驾破船 发布于 2010-11-25 12:58, 1082 次点击
#include <iostream>
using namespace std;
void time(int);
int main()
{
    int hours,minutes;
    cout<<"enter the number of hours : ";
    cin>>hours;
    cout<<endl;
    cout<<"enter the number of minutes : ";
    cin>>minutes;
    cout<<endl;
    time(hours),time(minutes);
    system("pause");
    return 0;
}
void time(int sys)
 {
     cout<<"time: "<<sys<<endl;
 }
本来是最后生成time:  9:28但是我这个却生成了time: 9   time :  28请各位给看看,不要笑我才学的,
9 回复
#2
玩出来的代码2010-11-25 14:19
调用两次time函数,你认为会输出"time:"几次。
#3
只手驾破船2010-11-25 15:01
要怎么写才能将两次输入的数字,通过这个函数一次调用出来
#4
laoyang1032010-11-25 15:31
#include <iostream>
using namespace std;
void time(int hour,int minutes);//输出两个整数传两个参数就可以啦
int main()
{
    int hours,minutes;
    cout<<"enter the number of hours : ";
    cin>>hours;
    cout<<endl;
    cout<<"enter the number of minutes : ";
    cin>>minutes;
    cout<<endl;
    time(hours,minutes);//这里调用一次就可以啦
    system("pause");
    return 0;
}
void time(int hour,int minutes)
{
     cout<<hour<<": "<<minutes<<endl;//连续输出传递过来的两个参数
}
楼主自己看哦   这个就可以的
#5
shi198719872010-11-25 18:39
四楼的写的不错!
#6
只手驾破船2010-11-25 20:35
谢谢啊朋友,明白是怎么的回事了
#7
cxjsxy2010-11-26 08:58
学习了。
#8
loveyouyin2010-11-26 13:39
很强啊 学习了 我也是刚看到门 还没有入呢
#9
vernonji2010-11-26 14:11
学习了!
#10
HAO。2012-08-02 23:54
哈!C++ Primer Plus中文版第二章最后一题!我也懂了,谢谢!
1