满意答案
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;
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();
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;
}
00分享举报