编译出错了,可是找不到错在哪里
#include <stdio.h>void main ()
{
int c, year,month,day;
printf("请输入年,月,日用,隔开\n");
scanf("%d,%d,%d",&year,&month,&day);
if (year%4==0&&year%100!=0||year%400==0)
{
if (month==1)
{
c=0+day;
printf("是第%d天\n",c);
}
else if (month==2)
{
c=31+day;
printf("是第%d天\n",c);
}
else if (month==3)
{
c=31+29+day;
printf("是第%d天\n",c);
}
else if (month==4)
{
c=31+29+31+day;
printf("是第%d天\n",c);
}
else if(month==5)
{
c=31+29+31+30+day;
printf("是第%d天\n",c);
}
else if (month==6)
{
c=31+29+31+30+31+day;
printf("是第%d天\n",c);
}
else if (month==7)
{
c=31+29+31+30+31+30+day;
printf("是第%d天\n",c);
}
else if (month==8)
{
c=31+29+31+30+31+30+31+day;
printf("是第%d天\n",c);
}
else if (month==9)
{
c=31+29+31+30+31+30+31+31+day;
printf("是第%d天\n",c);
}
else if (month==10)
{
c=31+29+31+30+31+30+31+31+30+day;
printf("是第%d天\n",c);
}
else if (month==11)
{
c=31+29+31+30+31+30+31+31+30+31+day;
printf("是第%d天\n",c);
}
else(month==12)
{
c=31+29+31+30+31+30+31+31+30+31+30+day;
printf("是第%d天\n",c);
}
}
else
{
if (month==1)
{
c=0+day;
printf("是第%d天\n",c);
}
else if (month==2)
{
c=31+day;
printf("是第%d天\n",c);
}
else if (month=3)
{
c=31+28+day;
printf("是第%d天\n",c);
}
else if (month==4)
{
c=31+28+31+day;
printf("是第%d天\n",c);
}
else if(month==5)
{
c=31+28+31+30+day;
printf("是第%d天\n",c);
}
else if (month==6)
{
c=31+28+31+30+31+day;
printf("是第%d天\n",c);
}
else if (month==7)
{
c=31+28+31+30+31+30+day;
printf("是第%d天\n",c);
}
else if (month==8)
{
c=31+28+31+30+31+30+31+day;
printf("是第%d天\n",c);
}
else if (month==9)
{
c=31+28+31+30+31+30+31+31+day;
printf("是第%d天\n",c);
}
else if (month==10)
{
c=31+28+31+30+31+30+31+31+30+day;
printf("是第%d天\n",c);
}
else if (month==11)
{
c=31+28+31+30+31+30+31+31+30+31+day;
printf("是第%d天\n",c);
}
else(month==12)
{
c=31+28+31+30+31+30+31+31+30+31+30+day;
printf("是第%d天\n",c);
}
}
}
C:\Program Files (x86)\Microsoft Visual Studio\hell wored\lianxi3\lianxi3.c(71) : error C2143: syntax error : missing ';' before '{'
C:\Program Files (x86)\Microsoft Visual Studio\hell wored\lianxi3\lianxi3.c(134) : error C2143: syntax error : missing ';' before '{'
执行 cl.exe 时出错.
lianxi3.obj - 1 error(s), 0 warning(s)
编译提示有一个错误,说”{”前面缺少”;”可是按提示看并不缺少“;”
谁给看看是怎么回事 先不管错误,你还是先优化代码吧。这代码拿的出手? 本帖最后由 jackz007 于 2019-10-13 17:39 编辑
这句代码有错误:
else(month==12)
应该是
else if (month==12)
整个代码中有 2 处,都是错的,都得修改。 ba21 发表于 2019-10-13 17:33
先不管错误,你还是先优化代码吧。这代码拿的出手?
刚刚开始学习,请多指教 ,不懂怎么优化 jackz007 发表于 2019-10-13 17:38
这句代码有错误:
else(month==12)
应该是
非常感谢,大侠指点;修改后果然不报错了 本帖最后由 jackz007 于 2019-10-13 18:34 编辑
谁能不死 发表于 2019-10-13 17:39
刚刚开始学习,请多指教 ,不懂怎么优化
能用智慧解决的问题,就不要用体力:
#include <stdio.h>
int main(void)
{
int MONTH[] = {31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31} ;
int d , k , year, month , day ;
printf("请输入年,月,日用,隔开:") ;
scanf("%d,%d,%d", & year , & month , & day) ;
for(d = day , k = 1 ; k < month ; k ++) d += MONTH ;
if(month > 2 && ((! (year % 4) && (year % 100) || (! year % 400)))) d ++;
printf("是第%d天\n",d) ;
}
页:
[1]