Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <algorithm>
- const std::string name = "Bob";
- bool isUpper(const std::string& input)
- {
- std::string str = input;
- str.erase(std::remove_if(str.begin(), str.end(), [](const char& c)
- {
- return !isalpha(c) || c == ' ';
- }), str.end());
- return std::all_of(str.begin(), str.end(), [](const char& c) {return std::isupper(c); });
- }
- size_t getResponse(const std::string& input)
- {
- size_t response = 5;
- if (isUpper(input))
- {
- if (input.find("?") != std::string::npos)
- response = 3;
- else
- response = 2;
- }
- else if (input.find("?") != std::string::npos)
- response = 1;
- else if (input == name)
- response = 4;
- return response;
- }
- int main()
- {
- /*
- 1 = question
- 2 = yell
- 3 = yell a question
- 4 = mention
- 5 = anything else
- */
- std::map<size_t, std::string> answers = { {1,"Sure."}, {2,"Whoa, chill out!"}, {3,"Calm down, I know what I'm doing!"},{4,"Fine. Be that way!"}, {5,"Whatever."} };
- std::map<size_t, std::string>::const_iterator it;
- std::string input;
- std::cout << "\t********** Talk with Bob... **********" << std::endl;
- do
- {
- std::cout << "You: ";
- std::getline(std::cin, input);
- if (input != "exit" && input != " ")
- {
- auto response = getResponse(input);
- it = answers.find(response);
- if (it != answers.end())
- {
- std::cout << name << ": " << it->second << std::endl;
- }
- }
- } while (input != "exit");
- __debugbreak();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement