Search code examples
c++arraysprimestoupper

C++ How do you make every third letter of a char array into an uppercase letter?


At the moment I have figured out how to make every vowel into a '!' and it does work. I have used a bool isVowel() function for that.

Now I want to uppercase every third letter. My array is char aPhrase[15] = "strongpassword":

while (aPhrase[i])
{
c=aPhrase[i];
putchar(toupper(c));
i+=3;
}

This just gets me SOPSRR instead of Str!ngP!sSw!Rd.


Solution

  • while (aPhrase[i]) {
        c = aPhrase[i];
        if (isVowel(c)) 
            c = '!';
        else if ((i % 3) == 0)
            c = toupper(c);
        putchar(c);
        ++i;
    }