condition not working, can anyone explain why that is?

后端 未结 4 417
失恋的感觉
失恋的感觉 2021-01-16 00:23

I just started learning C++ so i’m sure there is something obvious about this that i’m missing. I would love it if somebody could enlighten me. thank you!

Im trying

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-16 00:46

    Please change your Or conditions with And condition.

    #include 
    using namespace std;
    
    int main()
    {
        char answer{' '};
        std::cin>>answer;
    
        while (answer != 'n' && answer != 'N' && answer != 'Y' && answer != 'y') 
        {
            std::cout<<"Error: Please press 'Y' for yes and 'N' for no, followed by 'ENTER'. \n";
            std::cin>>answer;
        }
        return 0;
    }
    

提交回复
热议问题