Q:

Prevent from calling main() recursively in C++

I have a similar code to the following:
int main()
{
    'some
     code'
     motors();
}

int motors()
{
     if (condition)
     {
          'some
           code'
           main();
     }
     else if (condition)
     {
          'some
           code'
           main();
     }
     else
     {
           main();
     }
}

What could I do to prevent from calling main over and over? Could I make another function with main's code in it? 

A:

Calling main is undefined behavior in C++. You can wrap all the functions originally in main to another function. 
int main()
{
    wrapper();
}

void wrapper()
{
    //code originally in main
}

And whenever you need to call main, call this wrapper instead.
int motors()
{
     if (condition)
     {
         wrapper();
     }

