Hello everyone,
im just getting a little practice on working with strings recently so i decided to try my hand at a chatbot, i wrote a super simple example and one of the responses works... but none of the others do.
Code:
#include <iostream>
#include <string>
using namespace std;
//version 0.0.0.2 basic chatbot
string pb[3] = {"hello","how are you","what is your name"};
string rb[3] = {"Hi there","I am fine","My name is 01-1 Tranquil."};
void init()
{
//to be later filled with things.
}
void respond(const string inp)
{
int n = sizeof(pb) / sizeof(string);
for(int i = 0; i < n; i++)
{
if(!pb[i].compare(inp))
{
cout << rb[i] << "\n";
}
}
}
int main()
{
init();
int run = 1;
string inp;
while (run == 1)
{
cin >> inp;
respond(inp);
}
return 0;
}
thanks in advance.