My mini project is to make a chatbot; I have not google open sources, nor have I researched how to build. I'm trying this as to see how well I understand C++: Saying that;
I'm trying to make a "Box" of sort in which holds all "questions" that can be given and seeing "if" that "question" is "in" the "Box" it'll execute said code.
In Python it would be more or less:
Box = ["Yes", "YES", "yes", "yEs", "YeS", "yES"]
print "Will you be working today?"
response = raw_input("> ")
if response in Box:
print "Very well, then how can I assist you?"
So how would I go about doing so in C++. Or what is it called in C++? An array? A list? Vector? It's a bit confusing to differentiate those in C++.
For this I would consider converting the response to all lower-case then doing a straight comparison:
#include <string>
#include <cctype>
#include <functional>
#include <algorithm>
// convert string to lowercase
std::string lower_case(std::string s)
{
std::transform(s.begin(), s.end(), s.begin()
, std::ptr_fun<int, int>(std::tolower));
return s;
}
int main()
{
std::string response;
// ask question and get response
// now you don't need to look at every combination
if(lower_case(response) == "yes")
{
// positive response code
}
// etc...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With