微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。