jeudi 25 février 2021

C++ 11 Program: Main Menu keeps re-looping once wrong input is entered

I am working on a program that takes in point 2D, point 3D, line3D and line3D numbers from text file. This text file will then be run through the program in which its data can be sorted based on the user's preference. So far there has been no issues with the program other than the fact that the menu constantly loops again and again upon inputting an invalid input. Any help would be appreciated.

int displayMainMenu(string f, string sC, string sO)
{
    int choice;
    
    cout << endl << "NIL" << endl
         << "NIL" << endl
         << "--------------------------------------------" << endl
         << "Welcome to Program" 
         << endl << endl
         << "1) \t Read in data" << endl
         << "2) \t Specify filtering criteria (current: " << f << ")" << endl
         << "3) \t Specify sorting criteria (current: " << sC << ")" << endl
         << "4) \t Specify sorting order (current: " << sO << ")" << endl
         << "5) \t View data" << endl
         << "6) \t Store data" << endl
         << "7) \t Quit" << endl
         << endl << "Please enter your choice: ";
    cin >> choice;
    
    return choice;
}

int integerValidation(int option, string f, string sC, string sO)
{   
    switch (option)
    {
        case 1:
        case 2:
        case 3:
        case 4:
        case 5: 
        case 6:
        case 7: return option; 
        default: do
             {
                cout << endl << "You have entered an invalid menu option. Please re-enter..."
                             << endl;
                option = displayMainMenu(f, sC, sO);
                
             } while ((option != 1) || (option != 2) || (option != 3) ||
                      (option != 4) || (option != 5) || (option != 6) || (option != 7));
    }
    
    return option;
}

Aucun commentaire:

Enregistrer un commentaire