Ok, so I decided to try and write a simple chat bot.
To start, I made it so he will scan the string that you input, and see what emotion you have. (this is just the base, eventually he will read verbs and such)
So, here is the code...
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
string input;
int i = 0;
bool sad = false;
bool happy = false;
bool mad = false;
int found = 0;
int generalAmm = 7;
string sadwords[8] =
{
"im sad ",
"im very sad ",
"im sad.",
"im very sad.",
"makes me sad ",
"makes me very sad ",
"makes me sad.",
"makes me very sad."
};
string happywords[8] =
{
"im happy ",
"im very happy ",
"im happy.",
"im very happy.",
"makes me happy ",
"makes me very happy ",
"makes me happy.",
"makes me very happy."
};
string madwords[8] =
{
"im mad ",
"im very mad ",
"im mad.",
"im very mad.",
"makes me mad ",
"makes me very mad ",
"makes me mad.",
"makes me very mad."
};
bool findwords(string var)
{
for(i = input.find(var, 0); i != string::npos; i = input.find(var, i))
{
found++;
i++;
}
if (found >= 1)
{
i = 0;
return true;
}
else
{
i = 0;
return false;
}
}
int main(int argc, char *argv[])
{
start:
sad = false;
happy = false;
mad = false;
found = 0;
cout << ">> ";
getline(cin, input, '\n');
for(int g = 0; g < generalAmm; g++)
{
happy = findwords(happywords[g]);
}
for(int g = 0; g < generalAmm; g++)
{
sad = findwords(sadwords[g]);
}
for(int g = 0; g < generalAmm; g++)
{
mad = findwords(madwords[g]);
}
if (sad == true && happy == false)
cout << "Im sorry your sad.\n";
else if (happy == true && sad == false)
cout << "That's great!\n";
else if (sad == true && happy == true || mad == true && happy == true)
cout << "It sounds like you have mixed emotions!\n";
else if (sad == false && happy == false && mad == true)
cout << "Wow, thats a serious emotion.\n";
goto start;
system("PAUSE");
}
Now, the weird part is that, it doesn't let you say your happy because it just says "It sounds like you have mixed emotions!"
even though your only happy and I want it to say that if your happy and sad.
Every other emotion works, but not happy.
Why is it doing this?