在 C中使用 Switch-Case 语句时遇到问题;

发布于 2024-12-18 03:15:10 字数 613 浏览 2 评论 0原文

谁能告诉我为什么我不能得到这个菜单让我做出选择?它从让我做出正确的选择跳到“错误的选择”。预先感谢您的帮助,我一定会亲自感谢您。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰雪之触 2024-12-25 03:15:10

您可能正在阅读 \n 因为 fflush(stdin); 是错误的

相反,请尝试:

scanf(" %c", &input);
       ^

有许多与此相关的 C 常见问题解答条目,这里有一个解释了如何刷新标准输入

It's likely you're reading an \n because fflush(stdin); is wrong.

Instead try:

scanf(" %c", &input);
       ^

There are numerous C FAQ entries about this, here's one that explains how to flush stdin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文