编译时没错,为什么一建立就错了呢?代码如下:
#include<stdio.h>mian()
{
int year,month,day,sum;
printf("Please enter a date:");
scanf("%d,%d,%d",&year,&month,&day);
if((year%4==0&&year%100!=0)||year%400==0)
{
printf("This year is a leap yaer.\n");
switch(month)
{
case 1:sum=day;
break;
case 2:sum=day+31;
break;
case 3:sum=day+31+29;
break;
case 4:sum=day+31+29+30;
break;
case 5:sum=day+31+29+30+31;
break;
case 6:sum=day+31+29+30+31+30;
break;
case 7:sum=day+31+29+30+31+30+31;
break;
case 8:sum=day+31+29+30+31+30+31+31;
break;
case 9:sum=day+31+29+30+31+30+31+31+30;
break;
case 10:sum=day+31+29+30+31+30+31+31+30+31;
break;
case 11:sum=day+31+29+30+31+30+31+31+30+31+30;
break;
case 12:sum=day+31+29+30+31+30+31+31+30+31+30+31;
break;
default:sum=-1;
}
if(sum=-1)
printf("Data error!\n");
else
printf("Today is %d days of this year!\n",sum);
}
else
{
printf("This year is a nonleap year.\n");
switch(month)
{
case 1:sum=day;
break;
case 2:sum=day+31;
break;
case 3:sum=day+31+28;
break;
case 4:sum=day+31+28+30;
break;
case 5:sum=day+31+28+30+31;
break;
case 6:sum=day+31+28+30+31+30;
break;
case 7:sum=day+31+28+30+31+30+31;
break;
case 8:sum=day+31+28+30+31+30+31+31;
break;
case 9:sum=day+31+28+30+31+30+31+31+30;
break;
case 10:sum=day+31+28+30+31+30+31+31+30+31;
break;
case 11:sum=day+31+28+30+31+30+31+31+30+31+30;
break;
case 12:sum=day+31+28+30+31+30+31+31+30+31+30+31;
break;
default:sum=-1;
}
printf("Today is %d days of this year!\n",sum);
}
}