标题:[求助]已知今天的日期(包含年、月、日),编程求得明天的日期(年、月、日 ...
取消只看楼主
小飞丫
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2007-11-8
 问题点数:0 回复次数:0 
[求助]已知今天的日期(包含年、月、日),编程求得明天的日期(年、月、日)
已知今天的日期(包含年、月、日),编程求得明天的日期(年、月、日)?
#include <stdio.h>
#include <iostream.h>// 包含setw() 的头文件, c++
#include <iomanip.h>
int leap(int year)//判断是否闰年
{
int leap;
if((year%4==0 && year %100!=0)|| year %400==0)leap=1;
else leap=0;
return leap;
}
int main()
{
int year,month,day;
int months[12]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<" 输入今天的年月日:"<<endl;
cin>>year;
cin>>month;
cin>>day;
if(leap(year)) months[1]=29;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:{
if(day==31){month++;day=1;}
else day++;
break;}
case 4:
case 6:
case 9:
case 11:{
if(day==30){month++;day=1;}
else day++;break;}
case 2:{
if(day==months[1]){month++;day=1;}
else day++;break;}//对二月特殊判断
case 12:{
if(day==31){year++;month=1;day=1;}
else day++;break;
}//对12月特殊判断,如果是31号,年也应加1
}
cout<<" 明天的年月日为:"<<endl;
cout<<setw(5)<<"年"<<setw(5)<<"月"<<setw(5)<<"日"<<endl;
cout<<setw(5)<<year<<setw(5)<<month<<setw(5)<<day<<endl;
return 0;
}除了这样写
还有没有简单点的啊
搜索更多相关主题的帖子: int year leap include month 
2007-11-12 14:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-185501-1-1.html




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

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