自己找题做,怎么限制二月份的输入
输入某年某月某日,判断这一天是这一年的第几天。
#include<iostream>
using namespace std;
int main()
{
int year = 0, month = 0, day = 0,sum=0;
int fer;
cout << "请输入年份:";
cin >> year;
cout << "请输入月份:";
cin >> month;
cout << "请输入日期:";
cin >> day;
sum = day;
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
fer = 29;
}
else
fer = 28;
if (month>=1 && month<=12 && day>0 && day < 32)
{
switch (month - 1)
{
case 11: sum += 30;
case 10: sum += 31;
case 9: sum += 30;
case 8: sum += 31;
case 7: sum += 31;
case 6: sum += 30;
case 5: sum += 31;
case 4: sum += 30;
case 3: sum += 31;
case 2: sum += fer;
case 1: sum += 31;
}
cout << year << "年" << month << "月" << day << "日" << "是这一年的第" << sum << "天!";
cout << " " << endl;
}
else
{
cout << "请输入正确的日期!!";
cout << " " << endl;
}
system("pause");
return 0;
}