/****************************************************************/ /* Title: Our First Chatbot */ /* Developer: Damian Gordon */ /* Date Created: 08/11/2024 */ /****************************************************************/ /* Description: This is our first Chatbot using rules */ /****************************************************************/ /* Modified by: Harry McGoona, 10/11/2024, Name feature */ /* Modified by: Hania Amear, 10/11/2024, Weather, recipe */ /* Modified by: Lok Ching Tam, 11/11/2024, Joke feature */ /* Modified by: Thomas Tobin, 15/11/2024, Rock,Paper,Scissors */ /* Modified by: Monike Ozeias Santos, 15/11/2024, Compliment */ /* Modified by: Nada Abassi, 16/11/2024, Biscuit ingredients */ /* Modified by: Dima Platsas, 17/11/2024, fact feature */ /* Modified by: Ivan Kubskyi, 17/11/2024, motivate feature */ /* Modified by: Allen Lapitan, 17/11/2024, Help count */ /* Modified by: Mohammed Younis, 18/11/2024, Travel question */ /* Modified by: Illya Mikava, 18/11/2024, Crypto values */ /* Modified by: Isaac Tuite, 18/11/2024, Oggy Oggy Oggy */ /* Modified by: Hamza Zeeshan, 18/11/2024, More motivation */ /* Modified by: Arshdip Chera, 19/11/2024, Spanish Option */ /* Modified by: Amy Webb, 19/11/2024, Mountain question */ /* Modified by: Seanne Oriemo, 24/11/2024, daily fact */ /* Modified by: Developer, XX/11/2024, Description */ /* Modified by: Developer, XX/11/2024, Description */ /****************************************************************/ #include #include #include #include #define MAX_INPUT_SIZE 100 time_t currentTime; struct tm *localTime; int help_count = 0; // Function to display a random fact void daily_fact() { // Array of sustainability facts const char *facts[] = { "Recycling one aluminum can saves enough energy to run a TV for 3 hours.", "Artificial Intelligence can optimize energy use in data centers by up to 40 percent.", "Using renewable energy sources reduces carbon footprints significantly.", "A 10% improvement in efficiency can save billions of dollars annually.", "Data centers powered by renewable energy can drastically reduce emissions." }; // Get the number of facts int num_facts = sizeof(facts) / sizeof(facts[0]); // Seed random number generator srand(time(0)); // Generate random index int random_index = rand() % num_facts; // Print random fact printf("Today's Fact: %s\n", facts[random_index]); } void respond(char *input) { if (strstr(input, "hello") != NULL || strstr(input, "hi") != NULL) { printf("Cbot: Hello! How can I help you today?\n"); } else if (strstr(input, "how are you") != NULL) { printf("Cbot: I'm just a program, but thanks for asking!\n"); } else if (strstr(input, "what is your name") != NULL) { printf("Cbot: I am the TU850/1 chatbot created in C!\n"); } else if (strstr(input, "hola") != NULL) { printf("Cbot: Muy buenas\n"); } else if (strstr(input, "como estas") != NULL) { printf("Cbot: Yo soy asi\n"); } else if (strstr(input, "thanks") != NULL) { printf("Cbot: You are very welcome.\n"); } else if (strstr(input, "If you could travel anywhere, where would you go?") != NULL) { printf("Cbot: I'd love to visit the source code of the universe.\n"); printf("Cbot: Imagine debugging reality itself!\n"); } else if (strstr(input, "my name is") != NULL) { input += 11; //This cuts "My name is " off the string printf("Cbot: Hi %s, that's a cool name.\n", input); } else if (strstr(input, "daily fact") != NULL) { daily_fact(); } else if (strstr(input, "What is the tallest mountain in the world?") != NULL) { input += 8; //This cuts "What is " off input[strlen(input)-1] = '\0'; //This cuts off the "?" at the end printf("Cbot: %s is Mount Everest in Nepal.\n", input); } else if (strstr(input,"what is the weather") !=NULL) { printf("Cbot:The weather today is dry with sunny spells.\n"); printf("Cbot: Winds will remain rather light.\n"); printf("Cbot: Highest temperatures of 10 to 12 degrees.\n"); } else if (strstr(input, "Oggy Oggy Oggy!") != NULL) { printf("Oi Oi Oi!\n"); } else if (strstr(input, "oggy oggy oggy!") != NULL) { printf("Oi Oi Oi!\n"); } else if (strstr(input, "Motivate me") != NULL) { printf("Quality is not an act, it is a habit!\n"); } else if (strstr(input, "how much is one bitcoin?") != NULL) { printf("Cbot: The current price of one Bitcoin is approximately $91,795.33 USD.\n"); printf("Cbot: Please note that cryptocurrency prices change frequently.\n"); } else if (strstr(input, "how much is one ethereum?") != NULL) { printf("Cbot: The current price of one Ethereum is approximately $3,109.36 USD.\n"); printf("Cbot: Please note that cryptocurrency prices are highly volatile and subject to change.\n"); } else if (strstr(input,"Can you give me an easy lemonade recipe?") !=NULL) { printf("Cbot: Sure! Here's a recipe for lemonade:\n"); printf("Cbot: You will need:\n"); printf("Cbot: Lemons\n"); printf("Cbot: Sugar\n"); printf("Cbot: Water.\n"); printf(" \n"); printf("Cbot: 1. Combine one cup each of sugar and water and\n"); printf(" cook over medium heat until the sugar dissolves.\n"); printf("Cbot: 2. Set the syrup aside to cool for about 10 minutes.\n"); printf("Cbot: 3. Combine the cooled syrup and freshly-squeezed lemon juice in a pitcher.\n"); printf("Cbot: 4. Add the remaining water and stir, then pour over ice and enjoy!\n"); } else if (strstr(input, "whoami") != NULL) { // Prompt the user for their name printf("Please enter your name: "); fgets(input, sizeof(input), stdin); // Remove the newline character if present input[strcspn(input, "\n")] = 0; // Greet the user with their name printf("Cbot: Hi %s, that's a cool name.\n", input); } else if (strstr(input, "I am") != NULL) { input += 5; //This cuts "I am " off the string printf("Cbot: Why do you think you are %s?\n", input); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); printf("Cbot: Tell me more.\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); printf("Cbot: I think you need to take time away from computers. Type in 'bye'\n"); } else if (strstr(input, "motivate me") != NULL) { const char *motivationalQuotes[] = { "Believe in yourself! You are capable of amazing things.", "Keep pushing forward; your hard work will pay off.", "Every day is a new opportunity to grow and improve.", "Success is not final, failure is not fatal: It is the courage to continue that counts.", "You are stronger than you think!" }; srand(time(NULL)); int randomIndex = rand() % 5; printf("Cbot: %s\n", motivationalQuotes[randomIndex]); } else if (strstr(input, "tell me a joke") != NULL) { printf("Cbot: Why can't a toe be 12 inches long?\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); printf("Cbot: Then it'd be a foot.\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); printf("Cbot: One more?\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); // second joke if (strstr(input, "yes") != NULL || strstr(input, "ok")) { printf("Cbot: What does a house wear?\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); printf("Cbot: Address!\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); printf("Cbot: One more?\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); input[strcspn(input, "\n")] = 0; // third joke (last one) if (strstr(input, "yes") != NULL || strstr(input, "ok")) { printf("Cbot: this is my last joke! :(\n"); printf("Cbot: Why do French people eat snails?\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); printf("Cbot: They don't like fast food.\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); } else { printf("Cbot: TT you don't like my jokes\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); } } else { printf("Cbot: TT you don't like my jokes\n"); } } // knock knock joke else if (strstr(input, "knock knock") != NULL) { printf("Cbot: Who's there?\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); input[strcspn(input, "\n")] = 0; printf("Cbot: %s who?\n", input); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); input[strcspn(input, "\n")] = 0; printf("Cbot: Hahahaha! That's funny!\n"); } else if (strstr(input, "haha") != NULL) { printf("Cbot: Hahaha\n"); } else if (strstr(input, "tell me a fact") != NULL) { printf("Cbot: Did you know that the circulatory system (heart, blood vessels, blood) is more than 60,000 miles long?\n"); printf("Cbot: Want to hear another fact? (yes/no)\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); input[strcspn(input, "\n")] = 0; if (strstr(input, "yes") != NULL || strstr(input, "ok") != NULL) { printf("Cbot: Octopuses have three hearts, blue blood, and eight tentacles? LOL!\n"); printf("Cbot: Want another fact? (yes/no)\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); input[strcspn(input, "\n")] = 0; if (strstr(input, "yes") != NULL || strstr(input, "ok") != NULL) { printf("Cbot: Cyprus has more cats than people (1.5 million vs 1.2 million.)\n"); printf("Cbot: Want one last fact? (yes/no)\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); input[strcspn(input, "\n")] = 0; if (strstr(input, "yes") != NULL || strstr(input, "ok") != NULL) { printf("Cbot: A day on Venus is longer than a year on Venus.\n"); printf("Cbot: That's all for now! Hope you enjoyed the facts.\n"); } else { printf("Cbot: Alright, no more facts for now. Have a great day!\n"); } } else { printf("Cbot: Okay, I'll save the rest for later. Have a great day!\n"); } } } else if (strstr(input, "help") != NULL) { printf("Cbot: The following statements are available:\n"); printf("> bye - exits the program\n"); printf("> Can you give me an easy lemonade recipe?\n"); printf("> Can you list the ingredients of biscuits?\n"); printf("> como estas - how are you in Spanish\n"); printf("> daily fact - gives a random daily fact\n"); printf("> give me a compliment - says nice things\n"); printf("> haha - laugh back\n"); printf("> hello - returns your greeting\n"); printf("> help - lists available commands\n"); printf("> hi - returns your greeting\n"); printf("> hola - Spanish greeting\n"); printf("> how are you - returns the computer's feelings\n"); printf("> how much is one bitcoin?\n"); printf("> how much is one ethereum?\n"); printf("> I am [feeling] - starts a discussion\n"); printf("> If you could travel anywhere, where would you go?\n"); printf("> knock knock - tells a joke\n"); printf("> motivate me - gives motivational quotes\n"); printf("> Motivate me - gives a motivational quote\n"); printf("> my name is [name] - compliments your name\n"); printf("> oggy oggy oggy! - Oi Oi Oi!\n"); printf("> Oggy Oggy Oggy! - Oi Oi Oi!\n"); printf("> rps - plays Rock, Paper, Scissors\n"); printf("> tell me a fact - tells facts\n"); printf("> tell me a joke - tells three jokes\n"); printf("> thanks - shows good manners\n"); printf("> What is the tallest mountain in the world?\n"); printf("> what is the weather - weather report\n"); printf("> what is your name - modest response\n"); printf("> what time is it - tells time\n"); printf("> whoami - checks your name\n"); help_count++; printf("You have typed 'help' %d time(s).\n", help_count); } else if (strstr(input, "what time is it?") != NULL) { // Get the current time time(¤tTime); // Convert to local time format localTime = localtime(¤tTime); // Print the time in a readable format printf("The current Date and Time are: %02d-%02d-%d %02d:%02d:%02d\n", localTime->tm_mday, localTime->tm_mon + 1, localTime->tm_year + 1900, localTime->tm_hour, localTime->tm_min, localTime->tm_sec); } else if (strstr(input,"Can you list the ingredients of biscuits?") !=NULL) { printf("cbot: Sure! here is a list of ingredients needed to make biscuits.\n"); printf("cbot: You will need:\n"); printf("cbot: > flour\n"); printf("cbot: > sugar\n"); printf("cbot: > butter\n"); printf("cbot: > milk\n"); printf("cbot: > baking soda\n"); printf("cbot: > chocolate chips\n"); } else if (strstr(input, "give me a compliment") != NULL) { // Array of compliments const char *compliments[] = { "You are an amazing person, and you brighten everyone's day!", "You have a fantastic sense of humour!", "Your kindness is truly inspiring!", "You have a unique way of seeing the world that is remarkable!", "You are capable of achieving anything you set your mind to!" }; srand(time(NULL)); // random index between 0 and 4 int randomIndex = rand() % 5; // Print a random compliment printf("Cbot: %s\n", compliments[randomIndex]); } else if (strstr(input, "rps") != NULL) { printf("Let's play\n"); printf("Input one of these:\n"); printf("Rock\n"); printf("Paper\n"); printf("Scissors\n"); printf("-----------\n"); printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); int r = rand() % 3; //Prints Computer pick if (r == 0) { printf("I picked: Rock\n"); } if (r == 1) { printf("I picked: Paper\n"); } if (r == 2) { printf("I picked: Scissors\n"); } if (r == 0) { if (strstr(input,"Rock") != NULL) { printf("Draw\n"); } else if (strstr(input,"Paper")!= NULL) { printf("You win\n"); } else if (strstr(input,"Scissors")!= NULL) { printf("You lose\n"); } else { printf("Invalid input try again"); } } if (r == 1) { if (strstr(input,"Rock") != NULL) { printf("You lose\n"); } else if (strstr(input,"Paper") != NULL) { printf("Draw\n"); } else if (strstr(input,"Scissors")!= NULL) { printf("You win\n"); } else { printf("Invalid input try again"); } } if (r == 2){ if (strstr(input,"Rock") != NULL) { printf("You win\n"); } else if (strstr(input,"Paper") != NULL) { printf("You lose\n"); } else if (strstr(input,"Scissors")!= NULL) { printf("Draw\n"); } else { printf("Invalid input run rps again\n"); } } } /*********** E X I T ***************/ else if (strstr(input, "bye") != NULL) { printf("Cbot: Goodbye! Have a great day!\n"); } else { printf("Cbot: I'm sorry, I don't understand that.\n"); } //Endif; } //End RESPOND; int main() { char input[MAX_INPUT_SIZE]; char Exit_Sentinel_YN = 'n'; printf(" \n"); printf(" *************************************\n"); printf(" * Welcome to the TU850/1 Chatbot! *\n"); printf(" *************************************\n"); printf(" Type 'bye' to exit.\n"); printf(" -------------------\n"); while (Exit_Sentinel_YN == 'n') { printf("You: "); fgets(input, MAX_INPUT_SIZE, stdin); // Remove newline character from input input[strcspn(input, "\n")] = 0; // WE ARE CALLING THE respond( ) FUCTION HERE respond(input); if (strcmp(input, "bye") == 0) { Exit_Sentinel_YN = 'y'; } //Endif; } //Endwhile; return 0; } //End.