//you want this in loop:
//may be nested loop help.
for(int i=0;i<len; ++i)
{
if (word[i] != 'a') //you said all vowel so here this condition is
{ //applicable only for 'a'. You gotta change it too.
char temp = word[0];
for (int j = i; j < len - i; j++)
{
word[j - 1] = word[j];
}
word[len - 1] = temp;
}
elsebreak;
}
Take the vowel checking logic and put it in its own function. You can call the function in the while loop and read the code at a more conceptual level, instead of polluting your code with mostly redundant and wordy checks:
#include <iostream>
bool isVowel(char c)
{
return (c == 'a' || c == 'A' ||
c == 'e' || c == 'E' ||
c == 'i' || c == 'I' ||
c == 'o' || c == 'O' ||
c == 'u' || c == 'U' );
}
int main()
{
char word[] = "programming";
int len = 11;
// The actual length of the string is 12 when considering the null terminator, but
// I don't want to consider that position at all in the following loop. The loop works
// by cycling consonants to the back of the word until the first vowel is reached. I
// never want to overwrite the null terminator, so I'll only consider the indicies that
// come before it.
while ( !isVowel(word[0]) ) //i.e. "While the first character in word is not a vowel..."
{
char temp = word[0];
for (int j = 1; j < len; j++)
{
word[j - 1] = word[j];
}
word[len - 1] = temp;
}
std::cout << word << std::endl;
return 0;
}