cctype manipulation logic error

My end goal is to write a program that only prints the letters in a string. through testing i found that digit will equal 0 when it is a letter (as i expected) but it wont enter the if statement. I know i have a dumb syntax error here and I'm missing it for some reason. Or maybe a larger logical error. Secondly in the the digit if the organization will take the lower case then make it an uppercase then back down to a lower again.


How can i enter the digit if when the char is a letter?
And how do i organize inside the digit if to make it possess each char as i have described?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
int main(void)
{
        using namespace std;
        string str;
        int size;
        bool digit, upper, lower;
        int counter = 0;

        cout << "What is the string that you would like to have manipulated? "; 
        getline(cin,str, '\n');

        size = str.size();
        cout << size << endl;
        
        for (int i = 0; i < size; i++)
        {       
        
                //cout << "dude";
                //check to see if the individual elements are digits
                digit = isdigit(str[i]);
                //if not dont print them
                if (digit == 0)
                {
                        //if char is lower case then make it uppercase
                        lower = islower(str[i]);
                        //cout << lower;
                        if (lower == 0)
                        {
                                cout << toupper(str[i]);
                                counter++;
                        }
                        //if uppercase then make it lower case
                        upper = isupper(str[i]);
                        else (upper = 0)
                        {
                                cout << tolower(str[i]);
                                counter++;
                        }
                }
        }       
}
~           
Topic archived. No new replies allowed.