Close a Repeating Main Function

Hi all. I'm very new to C++, really just been learning the past two days. I'm going through the tutorial on www.learncpp.com. I made a variation of his simple Calculator program from the tutorial, only mine uses a header file to organize all my functions. My problem is that I want my Calculator program to repeat the main function, but I also want to be able to close it from the console (maybe by typing "Exit" or something like that). I read in another forum that I can put "return main();" at the end of my main function to get it to repeat, but how do I get it to close without closing the cmd console?

This repeatedly does stuff until the <condition> in the while statement evaluates as true.

So using a while loop, your condition could be a simple bool called keepLooping, for example, which you set = true if the user enters "exit" to a prompt within the loop.

As an aside - calling a function from within itself, for example main() from within main(), is called recursion and is not the way to perform simple loops. You can read up on recursion if you want, but I suspect it's a topic for the future.

Have a go at the loop and let us know how you go!

Oh, and the cmd console will close if you exit the program. If you want the console to hang around so you can see any results before it closes, you can add a final call to a read-line function, such as getch() or read from cin - anything that requires the user to provide input and so pauses execution.