C++ codes

I need a code for my menu that lets say I open the start game section well in start game I have press 0 to go back and press 1 to make a new game, how can I make it where press 1 to start a new game will open with the stuff inside of it, get what I mean?
closed account (N36fSL3A)
Why don't you make a game class, make that into a pointer and once you want to create a new game you can just use the 'new' operator.

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
class Game
{
    // Your game code
};

int main()
{
    // A pointer to the game class
    Game* game;    

    char value;
    std::cin >> value;
    if(value == 0)
    {
        // Your code to go back.
    }
    else if(value == 1)
    {
        game = new Game;
    }
    // Your game code should run once you called the class functions
    game->Loop();
    
    // Free the memory you allocated.
    delete game;

    return 0;
}


EDIT - Lol I forgot the return value.
Last edited on by Fredbill30
Topic archived. No new replies allowed.