dimanche 12 janvier 2020

program exiting suddenly, what is wrong with this?

after i give the input to the mainMenu function, the program stops suddenly. i earlier ran the program with mainMenu as a member function of Game class, that time it worked fine. please help.

class Game
{
protected:
    bool gameRunning;
    int userOption;
    //...
public:
    int currentLevel;
    Game();
    ~Game();
//Functions
    int randBetween(int minVal, int maxVal);
    int friend mainMenu(Game obj);
//Accessors
    bool isRunning();
//Modifiers
};

int mainMenu(Game game)
{
    cout << "+-----------------------+" << endl;
    cout << "| = High Score Hunter = |" << endl;
    cout << "+-----------------------+" << endl;
    cout << "| Start Game\t: 1\t|" << endl;
    cout << "| High Score\t: 2\t|" << endl;
    cout << "| Exit\t\t: 3\t|" << endl;
    cout << "+-----------------------+" << endl;
    cout << "Enter your choice: ";     //after i give this input, the program crashes
    cin >> game.userOption;
    system("cls");

    switch (game.userOption)
    {
    case 1:
        game.gameRunning = true;
        break;
    case 2:
        cout << "display high score" << endl;
        break;
    case 3:
        break;
    default:
        cout << "INVALID INPUT!" << endl;
        break;
    }
    return game.userOption;
}

Aucun commentaire:

Enregistrer un commentaire