My assignment requires me to create a noughts and crosses program. I have managed to get all features working but I wish to add the ability to write to a text file, and call upon said file within a switch case (the switch case is used for the main menu). Writing the file is not a problem however when it comes to reading it I get 'E0546 transfer of control bypasses initialization of:'.
I have tried containing the switch case {} which allows the program to run but the input is not recognised as being correct.
do    //Do at least once (do loop) - contains the 'game loop'
{
    mainMenu();
    switch (menuChoice)
    {
    case 1:
        cout << "\t\t\t\t\t" << "Please enter your name" << endl;
        cout << "\t\t\t\t\t" << ">>" << endl;
        cin >> playerNames[1];
        init();                                                //Clear the grid and set to player one
        do {
            playerNames[2] = "Computer";
            system("color 03");                                //Change text colour to blue
            system("cls");                                     //Clear the screen
            DisplayGrid();                                     //Display grid to screen
            DisplayInput();                                    //Display input options relevant to single player
            CheckInput();                                      //Check player input                                    
            CheckStatus();                                     //Checks game status
            easyAI();                                          //Computer turn that randomly fills a square
            CheckStatus();
            system("cls");
        } while (toupper(input) != 'F' && toupper(input) != 'M');                              //Checks the player hasn't quit or returned to menu
    case 2:
        cout << "\t\t\t\t\t" << "Player one please enter your name" << endl;
        cout << "\t\t\t\t\t" << " >>";
        cin >> playerNames[1];
        cout << "\t\t\t\t\t" << "Player two please enter your name" << endl;
        cout << "\t\t\t\t\t" << " >>";
        cin >> playerNames[2];
        init();                                                //Clear the grid and set to player one
        do {
            system("color 03");                                //Change text colour to blue
            system("cls");                                     //Clear the screen
            DisplayGrid();                                     //Display grid to screen
            DisplayInput();                                    //Display input options relevant to multiplayer
            CheckInput();                                      //Check player input
            CheckStatus();                                     //Checks game status
            system("cls");
        } while (toupper(input) != 'F' && toupper(input) != 'M');                              //Checks the player hasn't quit or returned to menu
        break;
    case 3:
        howToplay();
        break;
    case 4:
        runProg = false;
        return 0;
        break;
    case 5:
        ifstream reader("score.txt");                       
        if (!reader)
        {
            cout << "Error opening file" << endl;
        }
    default:
        cout << "Please use the correct input from the available choices" << endl;
        system("pause");
    }
} while (toupper(input) != 'F');
return 0;
system("pause");
}
 
     
    