在 C中使用 Switch-Case 语句时遇到问题;
谁能告诉我为什么我不能得到这个菜单让我做出选择?它从让我做出正确的选择跳到“错误的选择”。预先感谢您的帮助,我一定会亲自感谢您。
printf("Welcome to the Inventroy Control System");
printf("\nPlease make a selection");
printf("\n\n\ta) Display Inventory");
printf("\n\tb) Add New Items");
printf("\n\tg) Exit");
printf("\nSelect what you would like to do");
printf("\nOption Chosen: ");
fflush(stdin);
scanf("%c", &input);
input = toupper(input);
switch(input)
{
case 'A':
{
funa(j,a);
break;
}
case 'B':
{
j = funb(amount,a);
break;
}
case 'G':
{
fung();
break;
}
default:
{
printf("\nWrong Selection");
}
}
can anyone tell me why i can't get this menu to let me make a selection? It skips from letting me make an option right to "Wrong Selection". Thanks in advance for the help, i'll make sure to thank you personally.
printf("Welcome to the Inventroy Control System");
printf("\nPlease make a selection");
printf("\n\n\ta) Display Inventory");
printf("\n\tb) Add New Items");
printf("\n\tg) Exit");
printf("\nSelect what you would like to do");
printf("\nOption Chosen: ");
fflush(stdin);
scanf("%c", &input);
input = toupper(input);
switch(input)
{
case 'A':
{
funa(j,a);
break;
}
case 'B':
{
j = funb(amount,a);
break;
}
case 'G':
{
fung();
break;
}
default:
{
printf("\nWrong Selection");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能正在阅读
\n
因为fflush(stdin);
是错误的。相反,请尝试:
有许多与此相关的 C 常见问题解答条目,这里有一个解释了如何刷新标准输入。
It's likely you're reading an
\n
becausefflush(stdin);
is wrong.Instead try:
There are numerous C FAQ entries about this, here's one that explains how to flush stdin.