主题:急求
wolf赵帅
[专家分:70] 发布于 2010-11-08 23:29:00
# include <stdio.h>
void main()
{ enum season{spring=1,summer,autumn,winter}s;
switch(s)
{ case spring:printf("Spring\n");break;
case summer :printf("Summer\n");break;
case autumn:printf("Autumn\n");break;
case winter:printf("Winter\n");break;
}
}
为什么没有输出结果?请高手们解答!
回复列表 (共3个回复)
沙发
bruceteen [专家分:42660] 发布于 2010-11-09 08:34:00
s没赋值
板凳
lovesky303 [专家分:120] 发布于 2010-11-09 09:26:00
#include <stdio.h>
void main()
{
enum SEASON
{
spring=1,
summer,
autumn,
winter
}s;
s = 1;//在这里要对枚举的变量赋值的
//s = 2;
//s = 3;
//s = 4;
switch(s)
{
case spring:
printf("Spring\n");break;
case summer:
printf("Summer\n");break;
case autumn:
printf("Autumn\n");break;
case winter:
printf("Winter\n");break;
default:
break;
}
}
3 楼
niufujun [专家分:50] 发布于 2010-11-09 21:47:00
对s赋值时要强制转换类型,
#include <stdio.h>
void main()
{
enum SEASON
{
spring=1,
summer,
autumn,
winter
}s;
s=SEASON(1);//在这里要对枚举的变量赋值的 对s赋值时要强制转换类型
//s = 2;
//s = 3;
//s = 4;
switch(s)
{
case spring:
printf("Spring\n");break;
case summer:
printf("Summer\n");break;
case autumn:
printf("Autumn\n");break;
case winter:
printf("Winter\n");break;
default:
break;
}
}
我来回复