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

209 Views Asked by At

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.

1

There are 1 best solutions below

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