求助大神们,VS2015写的C语言程序出了问题
我想写比较两个日期先后的程序,但出现出乎意料的结果,就是不管哪一年的2月6号都会被认为是错误的,并且还不按我所说的错误处理方法printf("\nThe date does not exist!\tPLease input again!\n\n");为此我还特意写了一个测试程序来验证,发现从0年到10000年的2月6号都会出现如此反常状况。
麻烦大神们帮我看一下
struct date
{
int day;
int month;
int year;
}day[2];
int isleap(int year); //判断是否闰年
int dateexist(struct date day); //判断日期输入是否正确
main()
{
int i=1,feb=0;
while (i==1)
{
printf("Please input the date now:\n");
printf("Day Month Year\n");
scanf_s("%d %d %d", &day[0].day, &day[0].month, &day[0].year);
i = dateexist(day[0]);
}
i = 1;
printf("\n\n");
while (i == 1)
{
printf("PLease input the date you want to:\n");
printf("Day Month Year\n");
scanf_s("%d %d %d", &day[1].day, &day[1].month, &day[1].year);
i = dateexist(day[1]);
}
printf("\n\n");
if (day[1].year > day[0].year)
{
printf("%d.%d.%d the future of %d.%d.%d.\n",day[1].month,day[1].day,day[1].year, day[0].month, day[0].day, day[0].year);
}
else if (day[1].year < day[0].year)
{
printf("%d.%d.%d the past of %d.%d.%d.\n", day[1].month, day[1].day, day[1].year, day[0].month, day[0].day, day[0].year);
}
else if (day[1].year == day[0].year)
{
if (day[1].month > day[0].month)
{
printf("%d.%d.%d the future of %d.%d.%d.\n", day[1].month, day[1].day, day[1].year, day[0].month, day[0].day, day[0].year);
}
else if (day[1].month < day[0].month)
{
printf("%d.%d.%d the past of %d.%d.%d.\n", day[1].month, day[1].day, day[1].year, day[0].month, day[0].day, day[0].year);
}
else if (day[1].month == day[0].month)
{
if (day[1].day > day[0].day)
{
printf("%d.%d.%d the future of %d.%d.%d.\n", day[1].month, day[1].day, day[1].year, day[0].month, day[0].day, day[0].year);
}
else if (day[1].day < day[0].day)
{
printf("%d.%d.%d the past of %d.%d.%d.\n", day[1].month, day[1].day, day[1].year, day[0].month, day[0].day, day[0].year);
}
else if (day[1].day == day[0].day)
{
printf("It's today.\n");
}
}
}
getchar();
getchar();
}
int isleap(int year)
{
int judge;
judge = ((year % 172800 == 0) || (year % 4 == 0 && year % 100 != 0) || (year % 1000 == 0 && year % 400 == 0)) ? 1 : 0;
return judge;
}
int dateexist(struct date day)
{
int i=0,feb=0;
i = (day.month > 0 && day.month < 13) ? 0 : 1;
if (isleap(day.year))
{
feb = 29;
printf("Leap Year\n");
}
else
{
feb = 28;
printf("Common Year\n");
}
if (i == 0)
{
switch (day.month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
i = (day.day <= 0 || day.day > 31) ? 1 : 0; break;
case 4:
case 6:
case 9:
case 11:
i = (day.day <= 0 || day.day > 30) ? 1 : 0; break;
case 2:
i = (day.day <= 0 || day.day > feb) ? 1 : 0; break;
}
}
if (i == 1)
printf("\nThe date does not exist!\tPLease input again!\n\n");
}