如果输入既不是字符c也不是h让我无法工作,我想给出错误信息!我查了一些其他的答案,但他们大多使用throw/ catch方法,我完全不理解.我刚开始编程和错误处理在第20章或第21章.尽可能以最简单的方式帮助我.
这就是我尝试过的:
cout << "Enter 'c'(even) or 'h'(odd): ";
cin >> your_guess;
if((your_guess != ('c' || 'h')) == false) {
cout << "Wrong Input. Game is restarting... " << endl;
// restart the game ...
}
Run Code Online (Sandbox Code Playgroud)
但它总是说Wrong Input. ....