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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChatBot
{
    class Program
    {
        static public double Intro(string hello)
        {
            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);
            Console.WriteLine();
            Console.WriteLine("What is your age:");
            double age = double.Parse(Console.ReadLine());
            return age;
        }
        static public double AgeCalc(double age)
        {
            if (age < 13)
            {
                Console.WriteLine("I am sorry, but I am unable to talk to you");
                Console.ReadLine();
                Console.Clear();
                
            }
            else 
            {
                Console.WriteLine("Great! I would love to talk to you, but I need to know your name");
                
            }
            return age;
        }
        static public string GetName(string UserName)
        {
            Console.WriteLine("Please enter your name:",UserName);
            string name = Console.ReadLine();
            Console.Clear();
            Console.WriteLine("Its nice to meet you {0}", name);
            Console.ReadLine();
            return name;
        }
        static public string Text()
        {
            Console.WriteLine("What would you like to talk about?");
            Console.ReadLine();
            string EInput = Console.ReadLine();
            return EInput;
           
        }
        static public string TextAnalyzer(string EInput)
        {
            if (EInput == "weather")
            {
                Console.WriteLine("I would love to talk about the weather");
                Console.ReadLine();
            }
            return EInput;
        }
        
        static void Main(string[] args)
        {
            double getAge = Intro("Age");
            Console.Clear();
            double CalcAge = AgeCalc((double)getAge);
            Console.ReadLine();
            GetName("Name");
            string ReadText = Text();
            TextAnalyzer((string)ReadText);
            



        }
    }
}

Change the TextAnalyzer method to this:

static public void TextAnalyzer(string EInput)
        {
            if (EInput == "weather")
            {
                Console.WriteLine("I would love to talk about the weather");
                Console.ReadLine();
            }
        }

Thanks

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#.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChatBot
{
    class Program
    {
        static public double Intro(string hello)
        {
            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);
            Console.WriteLine();
            Console.WriteLine("What is your age:");
            double age = double.Parse(Console.ReadLine());
            return age;
        }
        static public double AgeCalc(double age)
        {
            if (age < 13)
            {
                Console.WriteLine("I am sorry, but I am unable to talk to you");
                Console.ReadLine();
                Console.Clear();
                
            }
            else 
            {
                Console.WriteLine("Great! I would love to talk to you, but I need to know your name");
                
            }
            return age;
        }
        static public string GetName(string UserName)
        {
            Console.WriteLine("Please enter your name:",UserName);
            string name = Console.ReadLine();
            Console.Clear();
            Console.WriteLine("Its nice to meet you {0}", name);
            Console.ReadLine();
            return name;
        }
        static public string Text()
        {
            Console.WriteLine("What would you like to talk about?");
            Console.ReadLine();
            string EInput = Console.ReadLine();
            return EInput;
           
        }
        static public void TextAnalyzer(string EInput)
        {
            if (EInput == "weather")
            {
                Console.WriteLine("I would love to talk about the weather");
                Console.ReadLine();

            }
            if (EInput == "sports")
            {
                Console.WriteLine("The only thing I know about Sports is Giants Suck!");
                    Console.ReadLine();
            }
        }
        static void Main(string[] args)
        {
            double getAge = Intro("Age");
            Console.Clear();
            double CalcAge = AgeCalc((double)getAge);
            Console.ReadLine();
            GetName("Name");
            string ReadText = Text();
            TextAnalyzer((string)ReadText);
            



        }
    }
}

Use this code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChatBot
{
    class Program
    {
        static public double Intro(string hello)
        {
            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);
            Console.WriteLine();
            Console.WriteLine("What is your age:");
            int age = int.Parse(Console.ReadLine());
            return age;
        }
        static public double AgeCalc(double age)
        {
            if (age < 13)
            {
                Console.WriteLine("I am sorry, but I am unable to talk to you");
                Console.Clear();
            }
            else 
            {
                Console.WriteLine("Great! I would love to talk to you, but I need to know your name");
            }
            return age;
        }
        static public string GetName(string UserName)
        {
            Console.WriteLine("Please enter your name:",UserName);
            string name = Console.ReadLine();
            Console.Clear();
            Console.WriteLine("Its nice to meet you {0}", name);
            Console.WriteLine();
            return name;
        }
        static public string Text()
        {
            Console.WriteLine("What would you like to talk about?");
            string EInput = Console.ReadLine();
            Console.WriteLine();
            return EInput;
           
        }
        static public string TextAnalyzer(string EInput)
        {
            
            if (EInput == "weather")
            {
                Console.WriteLine("I would love to talk about the weather");
                Console.WriteLine("So how's the weather over there?");
            }
            if (EInput == "sports")
            {
                Console.WriteLine("The only thing I know about Sports is Giants Suck!");
                Console.WriteLine("What's your favorite sport?");
            }
            string answer = Console.ReadLine();
            return answer;

        }
        static void Main(string[] args)
        {
            double getAge = Intro("Age");
            Console.Clear();
            double CalcAge = AgeCalc((double)getAge);
            Console.ReadLine();
            GetName("Name");
            string ReadText = Text();
            string answer = TextAnalyzer(ReadText);

            Console.Clear();
            if(answer == "sunny" || answer == "cloudy")
            {
                 Console.WriteLine("Hmm.. I like {0} weather", answer); 
            }
            if (answer == "Football" || answer == "Cricket")
            {
                Console.WriteLine("You know what! I also like {0}", answer);
            }
            Console.ReadLine();

        }
    }
}

Thanks

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.