Function to convert lowercase s to uppercase in string(without #<algorithm>)

So I need to write a function to convert all lowercase character s's to uppercase and leave all other characters unchanged. Then return the transformed string. Everything I have read implements the <algorithm> header. Which we are not aloud to do. It's a practice assignment, not really for a grade but its frustrating me. Heres my code. Any help is appreciated.

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

// Function uppercase converts each lowercase character of s to its
// uppercase equivalent; all other characters are left unchanged. The
// transformed string is returned to the calling function.
string uppercase(string s);

int main()
{
string str;

while (getline(cin, str))
{
cout << "Before: " << str << endl;
str = uppercase(str);
cout << " After: " << str << endl;
}

return EXIT_SUCCESS;
}
Last edited on
You can just use a for loop and use islower and toupper. #include <cctype>
Topic archived. No new replies allowed.