0

The Chatbot is going to read their input and reply according to the input but the lowercase and uppercase aren't read as equals. I have been unsuccessful at finding how I would get this code to read uppercase letters as lowercase. How would I get it to recognize the input as lowercase?

#include <iostream>
#include <cstring>
#include <locale>
#include <limits>
#include <cstdlib> 

using namespace std;

int main

(int argc, char **argv)
{

string input;

cout << "Hello there" << endl;
{

for(;;)
{

std::cin >> input;

if (input == "hi")
cout << "hey what's up?" << endl;
if (input == "hey")
cout << "hey, what's up?" << endl;
if (input == "hello")
cout << "Hey, what's up?" << endl;
if (input == "how are you?")
cout << "I am good, how are you?" << endl;
if (input == "fine")
cout << "that's good" << endl;
if (input == "hru")
cout << "i am good, how are you?" << endl;
if (input == "good")
cout << "thats good" << endl;

        }
    }
}
iqstatic
  • 2,322
  • 3
  • 21
  • 39
  • 1
    Hello an welcome to Stackoverflow. Please first read this https://stackoverflow.com/help/how-to-ask to ask simplificate questions. Than you can have a look here https://stackoverflow.com/questions/313970/how-to-convert-stdstring-to-lower-case. In your case the c++ standard library documentation may help you in a better way than only the simple answer. If you take the meaning of the "==" operator you will see that you have to convert your strings before you can compare them. – pospich0815 Dec 01 '19 at 08:34

1 Answers1

3

By converting everything to lowercase before you make comparisons. To do this easily, #include <cctype> and use the tolower() function.

KyIe LiebIer
  • 408
  • 2
  • 12
  • 2
    Side note: `tolower` operates on `int`s so to be 100% safe you need to do a bit of casting. [This is covered in good documentation](https://en.cppreference.com/w/cpp/string/byte/tolower). – user4581301 Dec 01 '19 at 08:35