Going to Different Points in Code

First off, hello cplusplus.com :)

I've been creating a text based C++ game (very basic), and it requires the user to choose different options.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
if (dir == 1)
    {
        cout << "\nYou travel west. The moon lighting your path, you walk cautiosly down the road.\nNot seeing what is in front of you, you walk straight into a hole." << endl;
        cout << "\nWhat should you do?" << endl;
        cout << "\n1) Jump out." << endl;
        cout << "2) Climb out." << endl;
        cout << "3) Call for help." << endl;
        cout << "4) Do nothing.\n" <<endl;
        int c1;
        cin >> c1;
        if (c1 == 1)
        {
            cout << "\nYou have decided to jump." << endl;
        }
        else if (c1 == 2)
        {
            cout << "\nYou have decided to climb out." << endl;
        }
        else if (c1 == 3)
        {
            cout << "\nYou have decided to call for help. Your screams attract a nearby witch from\nthe east path. She picks you up and brings you to her lair." << endl;
        }
        else if (c1 == 4)
        {
            cout << "\nYou have decided to do nothing." << endl;
        }
        else
        {
            cout << "\nWrong answer." << endl;
        }
    }


After the user receives the 'Wrong answer' text, the program ends. However, i wish for the program to restart itself from a specific point. I'm using Code::Blocks and the GNU GCC compiler. How can i do this?

P.S. This game is nowhere near done ;)
Last edited on
You can use loops or a set of mutually recursive functions
http://www.cplusplus.com/doc/tutorial/control/#loops
so...
i should have something like:
1
2
3
do {
code
} while (n < 5);

right?
Yes, just notice that n needs to be declared before do or it won't be visible
1
2
3
4
declare n;
do {
code
} while (n<5);
And if you want to exit/restart the loop somewhere inside code ( without waiting to get to while (n<5) ) you can use break/continue
i tried to do this, but instead of restarting, the program just displays 'Wrong answer' over and over again, without stopping. Whats going on?
Topic archived. No new replies allowed.