【发布时间】:2013-04-10 09:19:56
【问题描述】:
我在关闭 C 中的程序之前要求确认时遇到了问题。我正在寻找程序以在输入 0 时启动确认退出循环但是程序当前在输入 0 时立即关闭而不是要求确认.
else if (input == 0)//if they chose to exit
{
printf("You have input 0, program is attempting to close, do you wish to continue? Press 0 for yes, any other number for no");
scanf_s ("%d", &secondinput);
if (secondinput == 0)
{
return;
}
else if (secondinput !=0)
{
print_menu(1);
scanf_s("%d", &input);
}
我猜我错过了一个更优雅的解决方案我已经尝试了一些东西,但无法让它工作。
正在发生的事情的示例: 输入 1 将整数添加到数组中 请求添加整数,例如8 按下 0 后,程序将显示“您是否希望关闭,0 表示是,任何其他整数表示否” 但是,当按下 0 时,程序会立即关闭。
【问题讨论】:
-
您是否尝试过在
if (secondinput == 0)上设置断点并查看secondinput的值? -
input和secondinput是如何声明的?它们是什么类型的? -
它们都是整数。
-
如果解决了,可以标记解决的答案,还是自己回答?
标签: c visual-studio return exit