bool isok = false;//用来记录日期是否正确
bool isrun = false;//用来判断是否是闰年
Console.Write("输入年:");
int year = int.Parse(Console.ReadLine());
Console.Write("输入月:");
int month = int.Parse(Console.ReadLine());
Console.Write("输入日:");
int day = int.Parse(Console.ReadLine());
bool isok = false;//用来记录日期是否正确
bool isrun = false;//用来判断是否是闰年
if (year >= 1759 && year < 9999)
{
if (month >= 1 && month <= 12)
{
if (month == 2)
{
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
{
if (day >= 1 && day <= 29)
{
isok = true;
isrun = true;
}
else
{
Console.WriteLine("应在29天范围之内");
}
}
else
{
if (day >= 1 && day <= 28)
{
isok = true;
}
else
{
Console.WriteLine("应在28天范围之内");
}
}
}
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
if (day >= 1 && day <= 31)
{
isok = true;
}
else
{
Console.WriteLine("日期应在31天之内");
}
}
if (month == 4 || month == 6 || month == 9 || month == 11)
{
if (day >= 1 && day <= 30)
{
isok = true;
}
else
{
Console.WriteLine("日期应在30天之内");
}
}
}
else
{
Console.WriteLine("月份不正确");
}
}
else
{
Console.WriteLine("年份不正确");
}
int sumday = 0;//第多少天
if (isok)//日期正确,计算天数
{
if (isrun)//是闰年
{
if (month == 1)
{
sumday = day;
}
if (month == 2)
{
sumday = 31 + day;
}
if (month == 3)
{
sumday = 31 + 29 + day;
}
if (month == 4)
{
sumday = 31 + 29 + 31 + day;
}
if (month == 5)
{
sumday = 31 + 29 + 31 + 30 + day;
}
if (month == 6)
{
sumday = 31 + 29 + 31 + 30 + 31 + day;
}
if (month == 7)
{
sumday = 31 + 29 + 31 + 30 + 31 + 30 + day;
}
if (month == 8)
{
sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + day;
}
if (month == 9)
{
sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + day;
}
if (month == 10)
{
sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;
}
if (month == 11)
{
sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;
}
if (month == 12)
{
sumday = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;
}
}
else
{
if (month == 1)
{
sumday = day;
}
if (month == 2)
{
sumday = 31 + day;
}
if (month == 3)
{
sumday = 31 + 28 + day;
}
if (month == 4)
{
sumday = 31 + 28 + 31 + day;
}
if (month == 5)
{
sumday = 31 + 28 + 31 + 30 + day;
}
if (month == 6)
{
sumday = 31 + 28 + 31 + 30 + 31 + day;
}
if (month == 7)
{
sumday = 31 + 28 + 31 + 30 + 31 + 30 + day;
}
if (month == 8)
{
sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + day;
}
if (month == 9)
{
sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + day;
}
if (month == 10)
{
sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;
}
if (month == 11)
{
sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;
}
if (month == 12)
{
sumday = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;
}
}
Console.WriteLine("第{0}天", sumday);
}
else
{
Console.WriteLine("已经日期不正确,算不出来!");
}
Console.ReadLine();
}