#include <iostream>
#include <string>
using namespace std;
int main() {
string question;
string answer;
// Define question and answer list
string questions[] = {"Hi", "How are you?", "What's your name?"};
string answers[] = {"Hello", "I'm fine, thanks.", "My name is Chatbot."};
// Get user input
while (true) {
cout << "Ask me a question: ";
getline(cin, question);
// Compare user input with questions
if (question == questions[0]) {
answer = answers[0];
} else if (question == questions[1]) {
answer = answers[1];
} else if (question == questions[2]) {
answer = answers[2];
} else {
answer = "I don't understand.";
}
// Give answer
cout << answer << endl;
}
return 0;
}
C++实现聊天机器人
最新推荐文章于 2024-04-27 13:34:07 发布