C++ 11 程序:一旦输入错误,主菜单就会不断重新循环

问题描述

我正在开发一个从文本文件获取点 2D、点 3D、line3D 和 line3D 数字的程序。然后,该文本文件将通过程序运行,其中的数据可以根据用户的偏好进行排序。到目前为止,除了在输入无效输入时菜单不断反复循环这一事实之外,该程序没有任何问题。任何帮助将不胜感激。

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 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;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)