c语⾔switch(choice),c语⾔while与switch的嵌套满意答案
Ridere
2017.01.11
采纳率:59%    等级:9
已帮助:2369⼈
你的choice类型不对,有两种修改⽅式
1. 把choice改成char型,switch中case换成字符:#include
int main(void)
{
char choice;
while ((choice=getchar()) != '#')
switch (choice)
{
case '1':
printf("you choice one.\n");
break;
case '2':
printf("you choice two.\n");
break;
switch的用法c语言case '3':
printf("you choice three.\n");
break;
case '4':
printf("you choice four.\n");
break;
default:
printf("you choice quit.\n");
break;
}
printf("you have quit the program.\n");
getchar();
return 0;
}
2. choice还是int型,⽤scanf输⼊choice,输⼊0结束#include int main(void)
{
int choice;
scanf("%d", &choice);
while (choice != 0) {
switch (choice)
{
case 1:
printf("you choice one.\n");
break;
case 2:
printf("you choice two.\n");
break;
case 3:
printf("you choice three.\n");
break;
case 4:
printf("you choice four.\n");
break;
default:
printf("you choice quit.\n");
break;
}
scanf("%d", &choice);
}
printf("you have quit the program.\n");
getchar();
getchar();
return 0;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。