Create your own user-defined function my_lower( ) that takes one string parameter and returns a string. The function should convert all the characters in the string passed through arguments to lowercase. Then, call that function in the main ( ) function where you should ask the user to input a string, pass that string to the function created by you, and display the result returned by your function.

Sample Input:

CodeSmasherS

Sample Output:

codesmashers

#include <iostream>
#include <string>

using namespace std;
string my_lower(string &str)
{
    for (int i = 0; i < str.length(); i++)
    {
        if (str[i] >= 65 && str[i] <= 92)
        {
            str[i] = str[i] + 32;
        }
    }
    return str;
}
int main()
{
    string str;
    getline(cin, str);
    cout << my_lower(str);
    return 0;
}

cpp programming exercise with solution
cpp programming exercise with solution