#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;
}
main 下的“if”语句,即使我输入的是或否或无效的答案,仍然会继续 if 语句。(无论我放什么,它仍然会在 if 语句中显示消息)。
if (questionThreeAnswer!= "yes" or "no"){
cout << "I asked for a yes or no! You betrayed me!" << endl;
return 0;
}
我知道这是一个简单的修复,但我不完全确定是什么。我有点菜鸟。此外,这可能是也可能不是做我想做的最有效的方法,但这主要是为了练习。