刚刚没注意看,case 语句后面须是常量表达式
你可以参考下这个程序:
#include <stdio.h>
void main()
{
int s1;char c;
while(1){
scanf("%d",&s1);
if(s1<=100) c='A';
if(s1>100&&s1<1000) c='B';
if(s1==1000) c='C';
switch(c)
{
case 'A': {printf("ok\n");break;}
case 'B': {printf("bbb\n");break;}
case 'C': {printf("aaa\n");break;}
default : printf("i don't know you want to do something!");
}
}
}
你可以参考下这个程序:
#include <stdio.h>
void main()
{
int s1;char c;
while(1){
scanf("%d",&s1);
if(s1<=100) c='A';
if(s1>100&&s1<1000) c='B';
if(s1==1000) c='C';
switch(c)
{
case 'A': {printf("ok\n");break;}
case 'B': {printf("bbb\n");break;}
case 'C': {printf("aaa\n");break;}
default : printf("i don't know you want to do something!");
}
}
}