Calling upon int main()

I am trying to make a text-based RPG game and part of it looks something like this:
1
2
if (hp<0){ cout 
<< "You died....";

Is it possible to call upon the main function to restart the game?
If not, is it possible to terminate a program through a function other than int main()?
You should put your game into a do-while loop whose condition is whether the user wants to play again.

1
2
3
4
5
6
do
{
    //game code
    cout << "Play Again? y/n" << endl;
    cin >> answer;
}while(answer == 'y' || answer == 'Y');
Last edited on
And to be explicit, do not call main()! It is not a normal function.
@L B
The problem is, I have more than one function in my game.
Unless I am mistaken, there is not a way to put a do while loop outside a function.
Last edited on
trexmix wrote:
Unless I am mistaken, there is not a way to put a do while loop inside a function.
You are mistaken, it is just the opposite: there is no way to put a do-while loop outside a function. It must be within the curly braces of a function to compile.
Last edited on
It was a mistake, I meant to write:
@L B
The problem is, I have more than one function in my game.
Unless I am mistaken, there is not a way to put a do while loop outside a function.
Why would you want to put it outside the function?

You know you can do this, right?
1
2
3
4
5
6
7
8
int main()
{
    do
    {
        DoSomething();
        TakeAnInt(5);
    }while(ReturnABool());
}
Im afraid I don't know what that would do.
I get my knowledge from what I consider a great book, but I'm not all the way through it.
I think I have a solution.
Can you call another void function from a first void function?
Of course. But you really should consider the loop, particularly the one given to you in the post above yours.
Topic archived. No new replies allowed.