Thread: simple chatbot problems

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    29

    simple chatbot problems

    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.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    >> does not read input with spaces in it. Perhaps you want getline instead.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    29
    Gracias.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Few simple problems
    By Crashie in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2009, 01:41 PM
  2. problems w/my simple function
    By generalt in forum C Programming
    Replies: 9
    Last Post: 05-08-2009, 10:45 AM
  3. Problems with a simple console game
    By DZeek in forum C++ Programming
    Replies: 9
    Last Post: 03-06-2005, 02:02 PM
  4. simple class, any problems?
    By Syneris in forum C++ Programming
    Replies: 6
    Last Post: 04-05-2002, 12:18 PM
  5. Simple Server problems...
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 08:51 PM