慕莱坞2287185
2018-07-29 11:45
#include <stdio.h>
int main()
{
int year = 2008;
int month = 8;
int day = 8;
int sum = 0;
switch(month)
{
case 1:
sum += 31;
break;
case 2:
if(year%4==0)
{
sum += 29;
}
else
{
sum += 28;
}
break;
case 3:
sum += 31;
break;
case 4:
sum += 30;
break;
case 5:
sum += 31;
break;
case 6:
sum += 30;
break;
case 7:
sum += 31;
break;
}
int sum += 8;
printf(%d,sum);
return 0;
}
switch是达到符合的case后顺序下去。加上break之后就是只在符合的情况中变化。所以当月份为8时…都没有符合的case。漏写default了。以及最后
int sum += 8;
printf(%d,sum);
应该是
sum += 8;
printf("%d",sum);
C语言入门
926208 学习 · 20797 问题
相似问题