| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2014 人关注过本帖
标题:C++提示用户输入年、月、日、小时、分、秒并显示出来,怎么添加输入条件?
取消只看楼主 加入收藏
c250484657
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-9-19
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
C++提示用户输入年、月、日、小时、分、秒并显示出来,怎么添加输入条件?
C++提示用户输入年、月、日、小时、分、秒。并显示出来。程序已经写好,但是想给他们加个条件,比如年的数字要大于0,月不能大于12,日不能大于31,小时不能超过12,分秒不能超过60.这个附加条件的程序要怎么加奥,我试了好久没添加成功。
#include <iostream>
using namespace std;

struct _time
{
    short year;
    short month;
    short day;
    short hour;
    short minute;
    short second;

};

int main( )
{
    struct _time t;
    cout<<"请输入年,月,日,时,分,秒:"<<endl;
    cin>>t.year>>t.month>>t.day>>t.hour>>t.minute>>t.second;
    cout<<t.year<<"年"<<t.month<<"月"<<t.day<<"日"<<t.hour<<"时"<<t.minute<<"分"<<t.second<<"秒"<<endl;
    return 0;
}
搜索更多相关主题的帖子: 条件 include minute second 
2011-09-21 20:54
c250484657
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-9-19
收藏
得分:0 
#include <iostream>
using namespace std;

struct _time
{
    short year;
    short month;
    short day;
    short hour;
    short minute;
    short second;

};

int main( )
{
    struct _time t;
    cout<<"请输入年,月,日,时,分,秒:"<<endl;
    cin>>t.year>>t.month>>t.day>>t.hour>>t.minute>>t.second;
    if
      0 < t.year &&t.month <= 12 && t.day <=31 &&t.hour<=24&& t.minute<=60 &&t.second<=60;
      cout<<t.year<<"年"<<t.month<<"月"<<t.day<<"日"<<t.hour<<"时"<<t.minute<<"分"<<t.second<<"秒"<<endl;
     else
      cout<<"you have enter a wrong time"<<endl;
      
    return 0;
}
这儿不会了。。。。求教
2011-09-21 20:55
快速回复:C++提示用户输入年、月、日、小时、分、秒并显示出来,怎么添加输入条 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011064 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved