#include<iostream>
using namespace std;
int main()
{
cout << "请输入年份 :" << endl;
int y; int i;//是否是闰年的标记1和0
cin >> y;
if (((y % 4 == 0) && (y % 100 != 0)) || ((y % 100 == 0) && (y % 400 == 0)))
//cout << "您输入的是闰年" << endl;
i = 1;
else
//cout << "这个年份不是闰年哦" << endl;
i = 0;
//输入月份并判断日期
int m; int d;
cout << "请输入月份 :" ;
cin >> m;
cout << "请输入日期 :";
cin >> d;
//判断数据是否错误
if (m == 2)
{
if (d < 1 || d > 29)
{
cout << "输入的日期不存在" << endl;
}
system("pause");
return 2;
}
if (m < 1 || m > 12 || d < 1 || d > 31) {
cout << "输入的日期不存在" << endl;
system("pause");
return 1;
}
switch (m) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10: if (d < 31 &&d >= 1) d++;
else(y, m++, d = 1);
break;
case 12:if (d < 31 && d >= 1) d++;
else (y++, m = 1, d = 1);
break;
case 4:
case 6:
case 9:
case 11:if (d < 31 && d >= 1) ++d;
else (y, m++, d = 1);
break;
case 2:
if (i = 1 && d >1 && d <= 28)
{
d = d + 1;
}
else {
if (i = 1 && d >1 && d == 29)
{
m = m + 1;
d = 1;
}
if (i = 0 && d > 1 && d < 27)
{
d = d + 1;
}
}
break;
}
cout << "您输入的日期的后一天是:" << y << "年" << m << "月" << d << "日" << endl;
system("pause");
return 0;
}
c++练习 日期的顺延显示
最新推荐文章于 2022-04-10 14:00:32 发布