So I recently finished a beginner'c course on C++, and wanted to make my own "chat bot" since apparently it's easy and been done a million times. The problem I'm having, is that when the user input matches more than one possibility in my 'if' statement, it issues the command more than once.
class response{
public:
void answer() {
string x;
cin >> x;
if (x=="Hello"||x=="hello"||x=="Hi"||x=="hi"||x=="hey"||x=="Hey") {
cout << endl << "Hello!" << endl << endl;
}
else {
cout << endl << "I didn't understand that." << endl << endl;
}
} };
For example, if you input: "hey hi", you get: "Hello! Hello!"
Or if you input "hey squid" you get "Hello! I didn't quite understand that."
And so on and so on. I'm wondering if there is any way to make it so that, unless your entire string matches the exact x== values, it will execute the else statement, and only execute it once.
Edit: The solution worked. Thanks for all the help! Some of you were asking about how I was using the class statement in main. I hope this helps clarify how I used it:
int main()
{
cout << "Hello! I am Drew Bot 1.0." << endl << endl;
for(;;){
response test;
test.answer();
}
}