
{
char ch;
printf("give me a letter of the alphabet,and i will give");
printf("an animal name\nbeginning with that letter") ;
printf(" please type in a letter;type # to end it\n");
while((ch = getchar()) != '#')
{
if(ch == '\n')
continue;
if('a' <= ch&&ch <= 'z')
switch (ch)
{
case'a':
printf("argali,hhhh\n");
break;
case'b':
printf("babirusa,hhh\n");
break;
case'c':
printf("coati,hhhh\n");
break;
case'd':
printf("desman,hhhh\n");
break;
case'e':
printf("echidna,hh\n");
break;
case'f':
printf("fisher,hhh\n");
break;
dafault:
printf("that's a stumper\n");
}
else
printf("i don't know\n");
while(getchar() != '\n')
continue;
printf("please type another letter or a #");
}
printf("bye\n");
return 0;
}
.cn/release/static/image/mid/ask/263781122926159.png 'CCDAD01D-C7C4-4D7C-B80E-49675934A520.png')
default是说如果你所有的case都不满足就执行default
这一条是为了防止Switchcase无法覆盖所有结果,或是简写不需要分支处理的条件判断
default就是case都不满足的话,会执行里面的语句