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

[求助]c++问题

dengtc 发布于 2007-05-14 14:48, 903 次点击
[求助]C++初级问题编写一个程序,要求用户输入小时数和分钟数.在main()函数中,将两个值传递给一个void函数,后者以下面这样的格式显示这两个值:
Enter number of hours:9
Enter number of minutes:28
Time: 9:28

请各位大哥帮帮忙!
19 回复
#2
x0012007-05-14 15:26

不知道是不是你要的那种额``
我是新手额````

只有本站会员才能查看附件,请 登录

#3
byebye122007-05-14 16:37
回复:(x001)不知道是不是你要的那种额`` 我是新手额...
#include<iostream.h>
int main()
{
int hours;
int minutes;
cout<<"-----------------------------------------------------------\n"
<<"输入小时数\n"
<<"-----------------------------------------------------------\n";
cin>>hours;
cout<<"-----------------------------------------------------------\n"
<<"输入分钟数\n"
<<"-----------------------------------------------------------\n";
cin>>minutes;
cout<<"-----------------------------------------------------------\n"
<<"Enter number of hours:"<<hours<<"\n"
<<"-----------------------------------------------------------\n"
<<"Enter number of minutes:"<<minutes<<"\n"
<<"-----------------------------------------------------------\n"
<<"time:"<<hours<<":"<<minutes<<"\n"
<<"-----------------------------------------------------------\n";
}



请问楼上的朋友,这些红色的是什么意思?是不是可以省略?
#4
PcrazyC2007-05-14 16:41
首先说一下,VOID不能是函数,是否个关键字.你可能说的是函数的返回值吧.

#include<iostream>
using namespace std;

void time(int hour;int minute)
{
cout<<hour<<":"<<minute<<endl;
}

int main()
{
int a,b;
cout<<"Enter number of hours:";
cin>>a;
cout<<Enter number of minutes";
cin>>b;
time(a,b);
return 0;
}

[此贴子已经被作者于2007-5-14 17:02:56编辑过]

#5
amdam230002007-05-14 16:44
#include<iostream.h>
int main()
{
int hours;
int minutes;
cout<<"输入小时数:\n"
cin>>hours;
cout<<"输入分钟数:\n"
cin>>minutes;
out<<"time:"<<hours<<":"<<minutes<<"\n"
return 0;
}

楼上的朋友,你漏了return 0;
怎么出现红线了??不会吧,哪有这些的呢
#6
PcrazyC2007-05-14 17:02
嗯,是忘了,我没有用编译器写,有时候没有注意这点小问题
#7
leeco2007-05-14 22:04
几位写了都有一些小问题没有考虑到,
按照习惯一点零一分应该是" 1:01",第一个1前面是一个空格,第二个1前面是一个0,从没看到过"1:1"这样的时间对吧。
#8
kisscjy2007-05-14 22:10

说得好~~
严重赞成楼上的~~~

#include<iostream>
using namespace std;

void time(int hour,int minute)
{
cout<<hour<<":";
if(minute<10)
cout<<"0"<<minute<<endl;
else
cout<<minute<<endl;

}

int main()
{
int a,b;
cout<<"Enter number of hours:";
cin>>a;
cout<<"Enter number of minutes:";
cin>>b;
time(a,b);
return 0;
}

#9
kisscjy2007-05-14 22:10

ls可真细心~~~

[此贴子已经被作者于2007-5-14 22:11:58编辑过]

#10
aipb20072007-05-14 23:11
#11
daluqiang2007-05-14 23:28
顶啊
#12
PcrazyC2007-05-14 23:43
忘了

[此贴子已经被作者于2007-5-15 11:31:09编辑过]


#13
yuyunliuhen2007-05-14 23:44
#14
PcrazyC2007-05-14 23:45
你笑什么
#15
yuyunliuhen2007-05-14 23:47

偶路过呀。。。
浇花。。。灌水。。。

#16
PcrazyC2007-05-14 23:56
现在好多人向我学习了--------灌水--------哪都灌
#17
aipb20072007-05-15 10:39
纯表情是不允许的哦!
#18
dengtc2007-05-15 11:12

谢谢kisscjy!!

#19
dengtc2007-05-15 11:31

#include<iostream>
using namespace std;
void time(int,int);
int main()
{
int a,b;
cout<<"Enter number of hours:";
cin>>a;
cout<<"Enter number of minutes:";
cin>>b;
time(a,b);
cin.get();
cin.get();
return 0;
}
void time(int hour,int minute)
{
cout<<"Time:"<<hour<<":";
if(minute<10)
cout<<"0"<<minute<<endl;
else
cout<<minute<<endl;
}

谢谢kisscjy!!!

#20
aipb20072007-05-15 11:41
看不下去了,把别人的求助贴搞水!

虽然我也在
1