I have this assignment:
Write a program with three functions: upper, lower, and reverse.
The upper function will accept a pointer to a string or C-string as an argument. It will step through each character in the string converting it (where necessary) to uppercase.

The lower function will accept a pointer to a string or C-string as an argument. It will step through each character in the string converting it (where necessary) to lowercase.

The reverse function will accept a pointer to a string or C-string. It will step through each character in the string converting uppercase characters to lowercase and lowercase characters to uppercase; numbers and special characters will be unaffected.

The program will execute the functions in the following order: upper, lower, and reverse.
When entering "AbCd", the upper function will return "ABCD"; the lower function will return "abcd"; and the reverse function will return "aBcD"

I beleive what is happening is that when function lower or reverse runs, it's not taking the orginal imput and changing it, but taking the imput from the last function. How do I prevent this?

#include <iostream>
#include <cctype>
using namespace std;

//function prototype
void upper(char *, const int);
void lower(char *, const int);
void reverse(char *, const int);

int main()
{
    // Constant for the size of a line of input
    const int SIZE = 26;
        // Array to hold a line of input
    char letters1[SIZE];


    // Prompt the user to enter a string.
    cout << "Please enter some upper and/or lower case letters (25 Characters Max): \n";
    cin.getline(letters1, SIZE);
    cout << "\n";

    upper(letters1, SIZE);
    lower(letters1, SIZE);
    reverse(letters1, SIZE);

    system("pause");
    return 0;
}



//Uppper function
void upper(char *letters2, int count)
{
    // Convert all lowercase characters to uppercase
    for (int count = 0; count < strlen(letters2); count++)
    {

        // convert it to an uppercase character.
        if (islower(letters2[count]))
        {
            letters2[count] = toupper(letters2[count]);
        }
    }

    // Display the converted line of input.
    cout << letters2 << endl;
    return;

}

//lower function
void lower(char *letters3, const int size)
{
    // Convert all lowercase characters to uppercase
    for (int count = 0; count < strlen(letters3); count++)
    {
            // Convert it to an lowercase character.
        if (isupper(letters3[count]))
        {
            letters3[count] = tolower(letters3[count]);
        }
    }

    // Display the converted line of input.
    cout << letters3 << endl;
    return;
}

// reverse function
void reverse(char *letters4, const int size)
{
    // Convert all lowercase characters to uppercase
    for (int count = 0; count < strlen(letters4); count++)
    {

        if (isupper(letters4[count]))
            letters4[count] = tolower(letters4[count]);

        else 
            if(islower(letters4[count]))
            letters4[count] = toupper(letters4[count]);
    }

    cout << letters4 << endl;
}

Each function changes the string 'letters1' in place. You'll need to save the results of each function so that the next call gets the original string.

Would i use like a static loacal or assign the origianl array to a new array and then delete it at the end, or something else?

Another thought: Your code does in fact do what the requirements say [but see below]. I believe it would be better to call them like this, to make sure that the functions get the same string:

// string = letters1
upper(string, SIZE);
// print string

//  rather than print from the function:
//    it should only do what's required:
//        the conversion

// string = letters1
lower(letters1, SIZE);
// print string

// string = letters1
reverse(letters1, SIZE);
// print string

Another small point: The functions get SIZE, even if the input is only 4 chars. It would be better to pass the actual length to the functions.

Your coding style (indents, bracket matching &c) is very good. Source code is for humand to read. Often, a programmer will have to look at code he wrote a year or two ago, and try to figure out what he meant.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.