-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'的類型是什麼? –