我想用menu
编写一个程序,以防用户选择1
直到4
我有简单的switch
:
int main() {
char str1[127];
char str2[127];
int result;
int option = 0;
while (option < 1 || option > 4)
{
printoptions();
scanf("%d", &option);
switch (option)
{
case 1:
printf("Please enter first string: ");
gets(str1);
printf("Please enter second string: ");
gets(str2);
// bla bla
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
break;
}
}
printf("\nPress any key to continue");
getch();
return 0;
}
所以我的问题是,在用户选择1
选项后,我可以看到此输出:
Please enter first string: Please enter second string:
为什么会这样?