我在关闭 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 将整数添加到数组中 请求添加整数,例如,按 0 时输入 8 程序旨在说明“您希望关闭吗,0 表示是,任何其他整数表示否”当按下 0 时,程序立即关闭。