【求助】关于switch的问题!
#include<stdio.h>void main()
{
int choice;
head:
printf("\t\t+---------------------+-------------------------+\n");
printf("\t\t| (1)苹果 | (2)西瓜 |\n");
printf("\t\t+---------------------+-------------------------|\n");
printf("\t\t| (3)exit(); | |\n");
printf("\t\t+---------------------+-------------------------+\n");
again:
printf("input your choice:");
scanf("%d",&choice);
switch(choice){
case 1:printf("你选的是苹果\n");goto head;break;
case 2:printf("你选的是西瓜\n");goto head;break;
case 3:exit(0);
default:printf("你输入有误,请重试:\n");goto again;break;
}
}
这里有个问题,就是我输入数字键不是1,2,3时会提示出错,并且重试,goto到again,可是为什么我输入不是数字,而是字符键程序会进入死循环,这是为什么???