So now you know how to validate criteria, run a loop and generate a random numbe
ID: 3593719 • Letter: S
Question
So now you know how to validate criteria, run a loop and generate a random number. In this activity, you will make a chatbot that talks to the user – if you would like a more complex example of this, search for Cleverbot and try having a short conversation with it. In this chatbot, allow the user to enter a string as a form of dialogue. Next, create some preset statements (at least five) that will be randomly selected as the response to the user’s dialogue. Run the program to see how the bot behaves. What are your opinions about this bot? Is it very believable during conversation? Probably not, but don’t worry! We will continue working with this in later Labs, and will create more chatbots with more complexity and realism.
Explanation / Answer
#include <iostream>
#include <string>
#include <ctime>
#include<stdlib.h>
int main()
{
std::string response[] = {
"I herd you!",
"So, You are talking to me.",
"Continue, I’m listening.",
"Very intresting conversation.",
"Tell me more..."
};
srand((unsigned) time(NULL));
std::string Input = "";
std::string Response = "";
while(1) {
std::cout << ">";
std::getline(std::cin, Input);
int n = rand() % 5;
Response = response[n];
std::cout << Response << std::endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.