我在 C++ 中的 while 循环有问题。while 循环总是第一次执行,但是当程序到达 while 循环的 cin 时,while 循环完美地工作我想知道我做错了什么。提前致谢。如果问题是noobish,我也很抱歉。我还是个初学者。
cout<<"Would you like some ketchup? y/n"<<endl<<endl<<endl; //Ketchup
selection screen
cin>>optketchup;
while (optketchup != "yes" && optketchup != "no" && optketchup != "YES" && optketchup != "Yes" && optketchup != "YEs" && optketchup != "yEs" && optketchup != "YeS"
&& optketchup != "yeS" && optketchup != "YeS" && optketchup != "yES" && optketchup != "y" && optketchup != "Y" && optketchup != "No" && optketchup != "nO"
&& optketchup != "NO" && optketchup != "n" && optketchup != "No");
{
cout<<"You have entered an entered "<<optketchup<<" which is an invalid
option. Please try again."<<endl;
cin>>optketchup;
}
if (optketchup == "yes" || optketchup == "YES" || optketchup == "Yes" || optketchup == "YEs" || optketchup == "yEs" || optketchup == "YeS"
|| optketchup == "yeS" || optketchup == "YeS" || optketchup == "yES" || optketchup == "y" || optketchup == "Y")
{
slcketchup == "with";
}
else
{
slcketchup == "without";
}
cout<<"Your sandwich shall be "<<slcketchup<<" ketchup."<<endl;
system ("pause");
再次提前感谢。