逻辑错误:循环重复自身但不重复程序 [英] Logical error: loop repeats itself but not the program

查看:48
本文介绍了逻辑错误:循环重复自身但不重复程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨! :D $ / $
程序运行但是一个问题就是循环,我想要的是整个程序再次运行但显然只有声明你想要程序再次运行吗?是[Y]或否[N]:又跑了。我试图使用goto但它没有用。无论如何我可以从我的do while语句跳到程序的开头,这样我就可以一遍又一遍地运行它?



我尝试了什么:



Hi! :D
program runs but one problem is the loop, what i want is for the entire program to run again but apparently only the statement "Do you want program to run again? Yes [Y] or No [N]: " runs again. I tried to use goto but it did not work. Any way I could jump from my do while statement to the beginning of the program so I can run it over and over?

What I have tried:

#include

推荐答案

从技术上讲,你无法循环 main 功能。但是你可以在循环内的 main 函数中包装所有的功能。例如

Technically you cannot loop your main function. However you may wrap, inside the main function all the functionality inside a loop. For instance
int main()
{
  // lot of stuff here
}



成为:


becomes:

int main()
{
   string answer;
   do
   {
     // lot of stuff here
     cout << "Do you like to continue?" << endl;
     cin >> answer;
   } while (answer == "yes");

}


这篇关于逻辑错误:循环重复自身但不重复程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆