This is a simple chatbot with built-in responses, internal to the program. You will build its responses by adding more case statements. Tested in Visual Studio 2017.
using System; using System.Threading; namespace ChatterBot { class Program { static void Main(string[] args) { bool shutdown = false; bool foundResponse; string inputValue; string outputValue = ""; string ai_Name = "Hal"; Console.WriteLine(ai_Name + ": Hello"); while (!shutdown) { foundResponse = false; Console.Write("User: "); inputValue = Console.ReadLine().ToLower(); Console.Write(ai_Name + ": "); // response data switch (inputValue) { case "hello": outputValue = "Hello to you! How are you?"; foundResponse = true; break; case "hi": outputValue = "Hi to you! How are you?"; foundResponse = true; break; case "yo": outputValue = "Yoooo to you! How are you?"; foundResponse = true; break; case "i'm good": outputValue = "That's great. What's new?"; foundResponse = true; break; case "i am good": outputValue = "That's great. What's new?"; foundResponse = true; break; case "exit": Console.WriteLine("Good bye"); Thread.Sleep(3000); //Console.ReadKey(); Environment.Exit(0); break; } // if response is found if (foundResponse) { Console.WriteLine(outputValue); } // if response is not found else { Console.WriteLine("I do not understand. Can you please rephrase it?"); } } } } }
Notes
An even better approach would be to read a static (flat) text file. The text file would contain all your data. For example, the format of the text file would be: input, output—or, user_input, computer_response.
Once you’ve mastered that, move on to parsing user input into nouns and verbs, expanding contracted words, and providing timestamps to user input.