Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So now you know how to validate criteria, run a loop and generate a random numbe

ID: 3593719 • Letter: S

Question

So now you know how to validate criteria, run a loop and generate a random number. In this activity, you will make a chatbot that talks to the user – if you would like a more complex example of this, search for Cleverbot and try having a short conversation with it. In this chatbot, allow the user to enter a string as a form of dialogue. Next, create some preset statements (at least five) that will be randomly selected as the response to the user’s dialogue. Run the program to see how the bot behaves. What are your opinions about this bot? Is it very believable during conversation? Probably not, but don’t worry! We will continue working with this in later Labs, and will create more chatbots with more complexity and realism.

Explanation / Answer

#include <iostream>
#include <string>
#include <ctime>
#include<stdlib.h>

int main()
{
    std::string response[] = {
        "I herd you!",
        "So, You are talking to me.",
        "Continue, I’m listening.",
        "Very intresting conversation.",
        "Tell me more..."
    };

    srand((unsigned) time(NULL));

    std::string Input = "";
    std::string Response = "";

    while(1) {
        std::cout << ">";
        std::getline(std::cin, Input);
        int n = rand() % 5;
        Response = response[n];
        std::cout << Response << std::endl;
    }

    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote