源自:4-17 switch与if语句的应用
请教 哪里错了
#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
int i =1;
int num=0;
if( ; i<month; i++)
{
switch(i)
{
case 1 :
num= num +31;
break;
case 2:
nun = num +29;
break;
case 3:
num=num+31 ;
break;
case 4 :
num = num +30;
break;
case 5:
num = num+31;
break;
case 6 :
num = num+30;
break;
case 7 :
num = num +31 ;
break;
}
num = num ;
}
else
{
printf("%dnum="num+day);
}
return 0;
}
提问者:IT强
2015-07-07 16:02
个回答
-
if( ; i<month; i++) //if--替换成for
{
switch(i)
{
case 1 :
num= num +31;
break;
case 2:
nun = num +29;
break;
case 3:
num=num+31 ;
break;
case 4 :
num = num +30;
break;
case 5:
num = num+31;
break;
case 6 :
num = num+30;
break;
case 7 :
num = num +31 ;
break;
}
num = num ; //这句啥意思?num+=day;
}
else
{
printf("%dnum="num+day); //不需要用else,直接printf("%dnum=",num);
}