-2
我正在制作一个关于cramer规则和矩阵的程序(太多空闲时间)。而在某个地方,我有这个问题,您需要输入“是”或“否”。如果我输入其他词语(例如lol),那么如果陈述或再次提出问题,则不会去其他词语。我如何限制答案只有是/否?C++ If/else if语句
cout << "There! you have now your first equation! is it " << a << "x+" << b << "y=" << e << "? Is it? Yes/No"<<endl;
cin >> z;
if (z== "No")
{
while (z== "No")
{
cout << "what is the value of x?"<<endl;
cin >> a;
cout << "\n"<<endl;
cout << "what is the value of y?"<<endl;
cin >> b;
cout << "\n"<<endl;
cout << "what is the value of answer?"<<endl;
cin >> e;
cout << "\n"<<endl;
cout << "There! you have corrected your first equation! is it " << a << "x+" << b << "y=" << e << "? Is it? Yes/No"<<endl;
cin >> z;
}
}
else if (z== "Yes")
{
cout << "We will now proceed!"<<endl;
}
我只是个初学者在C++中使用 代码块
而接受输入你无法控制的输入值。您必须先接受输入,然后才能检查接受的输入是否正确。您可以为错误的输入生成警告。 – Raman
'z'的类型是什么? –