Hi all,

I'm really new to programming, but i understand many basics... I have tried to set myself a goal of creating a "smartbot" that can hold a somewhat intelligent conversation with someone. So far, i can get the bot to recognise a name of a person. I've been trying to put in a function that basically reads that whenever a user types in a "bad word" (i.e. a swear, or something stupid like ur mom), it will respond saying, "No, (insert name here), thats not appropriate..." So far I have this code, but it says I have a parse error (comment is there). Also, should i put this function seperate from others in a header file and have the program check constantly for such "bad words"? And lastly, is there a way I can put all the "bad words" in a text file and have it go through the text file instead of writing out ALL the bad words in code?
PS: Please excuse the swears in there, i'm just trying to protect against people trying to mess with my bot ;) Thank you in advance for any help...
EDIT: I have put stars instead of swears...

HEre is the code:

#include <iostream>
#include <string>
using namespace std;

int main()
{
	string nameStr  = ""; //Not necessary to initialize
	string topicStr = ""; 
	string t2 = "mom";
	string t3 = "sex";
	string t4 = "* *";
	string t5 = "*";
	string t6 = "**";
	string t7 = "***";
	string t8 = "****";
	string t9 = "*****";
	string t10 = "******";




	cout << "Hi, my name is SMARTBOT... What's yours?" << endl;
	
	getline(cin, nameStr);

	cout << "Nice to meet you " << nameStr << ". What do you want to talk about?" <<endl;
	
	getline(cin, topicStr);
	
	
	if (topicStr == size_t find(t2)) //parse error!!!
		cout << "I don't think so " << nameStr << ". That's pretty, innapropriate..." << endl;
		
	else if (topicStr == "weather")
		cout << "I haven't decided yet... Maybe we should check the weather channel or weather.com" << endl;

	else if (topicStr == "nothing"||topicStr == "nothin"||topicStr == "notin")
		cout << "Then why did you bother opening the application? Leave..." << endl;
		
	else
		cout << "Let me check my memory... hold on 1 sec" << endl;
		
		system("PAUSE"); //this will pause the program so we can see what 
					 //happened before exiting out

	return 0;		 
					 
}
Member Avatar for iamthwee

>Also, should i put this function seperate from others in a header file and have the program check constantly for such "bad words"?

Yeah if you want.

>And lastly, is there a way I can put all the "bad words" in a text file and have it go through the text file instead of writing out ALL the bad words in code?

Yes it is called file i/o.

thnaks, i appreciate the help, but how would i create a program that would let the user type in things (like an instant messenger) and have the computer check for keywords and give automated replies. And how can i get it to "learn keywords" by asking the user to catogorise certain words in different files? Like Bad words, places, etc. And also, i still have the problem of the parse error at the moment...

Member Avatar for iamthwee

>how can i get it to "learn keywords"

You need to use AI...

ok... thank you for the help... but i don't think i'm phrasing this correctly... umm...
How can i create this program to be instant messenger like, so that the user can freely type, and the computer looks through databases to make replies... is my code ideal for this or not?
Also, am i using the find function correctly, and how can i use it in unison with file i/o to get the results desired?

int main()
{
	string nameStr  = ""; //Not necessary to initialize
	string topicStr = ""; 
	string t2 = "mom";
	string t3 = "sex";
	string t4 = "* *";
	string t5 = "*";
	string t6 = "**";
	string t7 = "***";
	string t8 = "****";
	string t9 = "*****";
	string t10 = "******";

I would suggest learning about arrays and STL containers in order to hold data, rather than creating a long list of variables holding all the words you want the program to remember. (With an STL container, such as a Vector or List you can dynamically add words to your collection as the program runs )

eg, this program retrieves a few lines of text from the user, stores them in a vector of strings, called my_dictionary, and outputs the stored text again at the end.

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    vector<string> my_dictionary;
    string a_word;

    const int num = 4;

    for( int i = 0; i < num; ++i )
    {
        getline( cin, a_word );
        my_dictionary.push_back( a_word );
    }

    for( int i = 0; i < num; ++i )
        cout << my_dictionary.at( i ) << ' ' ;
}

As for getting the computer to derive responses from your conversation, you can make that as simple or as complicated as you like... how you do it is up to you. One simple way to do it might be to create an STL <map> of words, along with their responses, then use the map as a lookup to determine the computer's reply.

as iamthwee said, you would do well to investigate AI, do a google search, which throws up a vast number of hits.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.