#include <iostream>
#include <string>
using namespace std;
string questionOneAnswer;
string questionTwoAnswer;
string questionThreeAnswer;
class quizAshton{
public:
string question1(){
cout << "What is your favorite food?" << endl;
cin >> questionOneAnswer;
return questionOneAnswer;
}
string question2(){
cout << "What is the name of someone you hate?" << endl;
cin >> questionTwoAnswer;
return questionTwoAnswer;
}
string question3(){
cout << "Hi! (yes or no)" << endl;
cin >> questionThreeAnswer;
return questionThreeAnswer;
}
};
int main()
{
quizAshton ashtonAnswers;
ashtonAnswers.question1();
ashtonAnswers.question2();
ashtonAnswers.question3();
if (questionThreeAnswer!= "yes" or "no"){
cout << "I asked for a yes or no! You betrayed me!" << endl;
return 0;
}
cout << "APPARENTLY your favorite food is " << questionOneAnswer << "... I guess I wouldn't really believe that unless it was eaten by " << questionTwoAnswer << "and is the cat ready...: " << questionThreeAnswer << endl;
return 0;
}
メインの下の「if」ステートメントは、yes または no または無効な回答を入力した場合でも、if ステートメントを続行します。(何を入れても、ifステートメント内にメッセージが表示されます)。
if (questionThreeAnswer!= "yes" or "no"){
cout << "I asked for a yes or no! You betrayed me!" << endl;
return 0;
}
これが簡単な修正であることは知っていますが、何が原因かは完全にはわかりません。私はちょっと初心者です。また、これは私がやろうとしていることを行うための最も効率的な方法かもしれませんし、そうでないかもしれませんが、これは主に練習用です.