943,082 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 775
  • C# RSS
Dec 31st, 2009
0

Help with C# Chat Bot

Expand Post »
Hi,
I am building a chat bot using C# and I am having problems with my Text Analyzation method. Can someone please take a look at my code and help me figure out what to do to fix it?

Thanks

C# Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ChatBot
  7. {
  8. class Program
  9. {
  10. static public double Intro(string hello)
  11. {
  12. Console.WriteLine("Hi, My name is Sid and I would love to talk to you, but first I need to know \n your age", hello);
  13. Console.WriteLine();
  14. Console.WriteLine("What is your age:");
  15. double age = double.Parse(Console.ReadLine());
  16. return age;
  17. }
  18. static public double AgeCalc(double age)
  19. {
  20. if (age < 13)
  21. {
  22. Console.WriteLine("I am sorry, but I am unable to talk to you");
  23. Console.ReadLine();
  24. Console.Clear();
  25.  
  26. }
  27. else
  28. {
  29. Console.WriteLine("Great! I would love to talk to you, but I need to know your name");
  30.  
  31. }
  32. return age;
  33. }
  34. static public string GetName(string UserName)
  35. {
  36. Console.WriteLine("Please enter your name:",UserName);
  37. string name = Console.ReadLine();
  38. Console.Clear();
  39. Console.WriteLine("Its nice to meet you {0}", name);
  40. Console.ReadLine();
  41. return name;
  42. }
  43. static public string Text()
  44. {
  45. Console.WriteLine("What would you like to talk about?");
  46. Console.ReadLine();
  47. string EInput = Console.ReadLine();
  48. return EInput;
  49.  
  50. }
  51. static public string TextAnalyzer(string EInput)
  52. {
  53. if (EInput == "weather")
  54. {
  55. Console.WriteLine("I would love to talk about the weather");
  56. Console.ReadLine();
  57. }
  58. return EInput;
  59. }
  60.  
  61. static void Main(string[] args)
  62. {
  63. double getAge = Intro("Age");
  64. Console.Clear();
  65. double CalcAge = AgeCalc((double)getAge);
  66. Console.ReadLine();
  67. GetName("Name");
  68. string ReadText = Text();
  69. TextAnalyzer((string)ReadText);
  70.  
  71.  
  72.  
  73.  
  74. }
  75. }
  76. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shmukle is offline Offline
2 posts
since Dec 2009
Dec 31st, 2009
0
Re: Help with C# Chat Bot
Change the TextAnalyzer method to this:

C# Syntax (Toggle Plain Text)
  1. static public void TextAnalyzer(string EInput)
  2. {
  3. if (EInput == "weather")
  4. {
  5. Console.WriteLine("I would love to talk about the weather");
  6. Console.ReadLine();
  7. }
  8. }

Thanks
Reputation Points: 61
Solved Threads: 71
Posting Whiz in Training
farooqaaa is offline Offline
283 posts
since Jul 2008
Dec 31st, 2009
0

Another question

Thanks! That worked perfectly. I have another question though, suppose I want to be able to input weather and then ask a question about the weather, how could I do that? (ex. weather ---> How is the weather where you live?). Sorry for all of the noob questions, I am still learning C#.

C# Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ChatBot
  7. {
  8. class Program
  9. {
  10. static public double Intro(string hello)
  11. {
  12. Console.WriteLine("Hi, My name is Sid and I would love to talk to you, but first I need to know \n your age", hello);
  13. Console.WriteLine();
  14. Console.WriteLine("What is your age:");
  15. double age = double.Parse(Console.ReadLine());
  16. return age;
  17. }
  18. static public double AgeCalc(double age)
  19. {
  20. if (age < 13)
  21. {
  22. Console.WriteLine("I am sorry, but I am unable to talk to you");
  23. Console.ReadLine();
  24. Console.Clear();
  25.  
  26. }
  27. else
  28. {
  29. Console.WriteLine("Great! I would love to talk to you, but I need to know your name");
  30.  
  31. }
  32. return age;
  33. }
  34. static public string GetName(string UserName)
  35. {
  36. Console.WriteLine("Please enter your name:",UserName);
  37. string name = Console.ReadLine();
  38. Console.Clear();
  39. Console.WriteLine("Its nice to meet you {0}", name);
  40. Console.ReadLine();
  41. return name;
  42. }
  43. static public string Text()
  44. {
  45. Console.WriteLine("What would you like to talk about?");
  46. Console.ReadLine();
  47. string EInput = Console.ReadLine();
  48. return EInput;
  49.  
  50. }
  51. static public void TextAnalyzer(string EInput)
  52. {
  53. if (EInput == "weather")
  54. {
  55. Console.WriteLine("I would love to talk about the weather");
  56. Console.ReadLine();
  57.  
  58. }
  59. if (EInput == "sports")
  60. {
  61. Console.WriteLine("The only thing I know about Sports is Giants Suck!");
  62. Console.ReadLine();
  63. }
  64. }
  65. static void Main(string[] args)
  66. {
  67. double getAge = Intro("Age");
  68. Console.Clear();
  69. double CalcAge = AgeCalc((double)getAge);
  70. Console.ReadLine();
  71. GetName("Name");
  72. string ReadText = Text();
  73. TextAnalyzer((string)ReadText);
  74.  
  75.  
  76.  
  77.  
  78. }
  79. }
  80. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shmukle is offline Offline
2 posts
since Dec 2009
Dec 31st, 2009
0
Re: Help with C# Chat Bot
Use this code:

C# Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ChatBot
  7. {
  8. class Program
  9. {
  10. static public double Intro(string hello)
  11. {
  12. Console.WriteLine("Hi, My name is Sid and I would love to talk to you, but first I need to know \n your age", hello);
  13. Console.WriteLine();
  14. Console.WriteLine("What is your age:");
  15. int age = int.Parse(Console.ReadLine());
  16. return age;
  17. }
  18. static public double AgeCalc(double age)
  19. {
  20. if (age < 13)
  21. {
  22. Console.WriteLine("I am sorry, but I am unable to talk to you");
  23. Console.Clear();
  24. }
  25. else
  26. {
  27. Console.WriteLine("Great! I would love to talk to you, but I need to know your name");
  28. }
  29. return age;
  30. }
  31. static public string GetName(string UserName)
  32. {
  33. Console.WriteLine("Please enter your name:",UserName);
  34. string name = Console.ReadLine();
  35. Console.Clear();
  36. Console.WriteLine("Its nice to meet you {0}", name);
  37. Console.WriteLine();
  38. return name;
  39. }
  40. static public string Text()
  41. {
  42. Console.WriteLine("What would you like to talk about?");
  43. string EInput = Console.ReadLine();
  44. Console.WriteLine();
  45. return EInput;
  46.  
  47. }
  48. static public string TextAnalyzer(string EInput)
  49. {
  50.  
  51. if (EInput == "weather")
  52. {
  53. Console.WriteLine("I would love to talk about the weather");
  54. Console.WriteLine("So how's the weather over there?");
  55. }
  56. if (EInput == "sports")
  57. {
  58. Console.WriteLine("The only thing I know about Sports is Giants Suck!");
  59. Console.WriteLine("What's your favorite sport?");
  60. }
  61. string answer = Console.ReadLine();
  62. return answer;
  63.  
  64. }
  65. static void Main(string[] args)
  66. {
  67. double getAge = Intro("Age");
  68. Console.Clear();
  69. double CalcAge = AgeCalc((double)getAge);
  70. Console.ReadLine();
  71. GetName("Name");
  72. string ReadText = Text();
  73. string answer = TextAnalyzer(ReadText);
  74.  
  75. Console.Clear();
  76. if(answer == "sunny" || answer == "cloudy")
  77. {
  78. Console.WriteLine("Hmm.. I like {0} weather", answer);
  79. }
  80. if (answer == "Football" || answer == "Cricket")
  81. {
  82. Console.WriteLine("You know what! I also like {0}", answer);
  83. }
  84. Console.ReadLine();
  85.  
  86. }
  87. }
  88. }

Thanks
Last edited by farooqaaa; Dec 31st, 2009 at 3:37 pm.
Reputation Points: 61
Solved Threads: 71
Posting Whiz in Training
farooqaaa is offline Offline
283 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: opening a connection to a database...
Next Thread in C# Forum Timeline: Using Word._Application.Quit Method





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC