Convert for comparison lowercase variables

Hello all,

I am trying to convert the string variable 'answer' with a specific array element. They both need to be either all upper or all lower case letters to ensure an accurate comparison. I'm getting the following error on line __: "invalid arguments' Candidates are; int tolower(int)." As these are strings, I don't quite understand the error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    string answer;
    int correct = 0;

    for(int x = 0; x < sizeofarrays; x++)
    {
        cout << "What is the capital of " << array1[x] << "?" << endl;
        getline(cin, answer);

        if (tolower(answer) == tolower(array2[x]))
        {
            cout << "Correct!" << endl;
            correct++;
        }
        else
        {
            cout << "Incorrect" << endl;
        }


Any and all help is greatly appreciated.
Pay attention to your types:

  “answer” is a “string”

but

  “tolower(int)” is a function taking an integer argument.

To overcome this, write a function. You can even use the same name.

1
2
3
4
5
6
std::string tolower( const std::string& s )
{
  std::string result( s );
  for (char& c : result) c = std::tolower( c );
  return result;
}

Now you can use it normally.

1
2
        if (tolower(answer) == tolower(array2[x]))
        {

Hope this helps.
Topic archived. No new replies allowed.