gpt4 book ai didi

c - 嵌套 do while 循环

转载 作者:行者123 更新时间:2023-11-30 18:38:05 27 4
gpt4 key购买 nike

所以我一直在尝试做一个带有更多子菜单的菜单。主菜单是一个 do while 循环,因此如果用户尝试输入不相关的输入,它会让他重新输入。我想知道是否可以对子菜单执行相同的操作,但即使我编写了有效的输入,子菜单循环也会继续进行。这是代码:

do
{

printf("Enter your choice: ");
scanf(" %d", &choice1);
switch (choice1)
{



case (1) :

do {
printf("4 printfs of choices");


printf("Enter your choice: ");
scanf(" %d", &choice2);


switch (choice2)
{

case (1):
{
stuff
}
break;

case (2) :
{
stuff
}
break;

case (3) :
{
stuff
}
break;

case (4) :
{
exit(0);
}

default :
{
printf("Sorry that is not a valid choice!\n");
}
break;
}
} while ((choice2 > 0) || (choice2 < 5));
break;

主循环还有一个 while 结束,但不是我的担忧

最佳答案

(choice2 > 0) || (choice2 < 5)

始终正确,您可能指的是 &&

关于c - 嵌套 do while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35044998/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com