Looks like you have a typo here, your code:
if(string[i]=='a'||string[i]=='A'||string[i]=='e'||string[i]=='E'||string[i]=='i'||string[i]=='I'||string[i]=='o'||string[i]=='O'||string[i]=='u'||string[i]=='U')
{
if(string[i+1]=='a'||string[i]=='A'||string[i]=='e'||string[i]=='E'||string[i]=='i'||string[i]=='I'||string[i]=='o'||string[i]=='O'||string[i]=='u'||string[i]=='U')
count++;
}
Notice the second if statement there, everything except the first condition is checking string[i] instead of string[i+1]. So if you have 'A' in string[i], then this will increment count no matter what is in string[i+1].
You want:
if(string[i]=='a'||string[i]=='A'||string[i]=='e'||string[i]=='E'||string[i]=='i'||string[i]=='I'||string[i]=='o'||string[i]=='O'||string[i]=='u'||string[i]=='U')
{
if(string[i+1]=='a'||string[i+1]=='A'||string[i+1]=='e'||string[i+1]=='E'||string[i+1]=='i'||string[i+1]=='I'||string[i+1]=='o'||string[i+1]=='O'||string[i+1]=='u'||string[i+1]=='U')
count++;
}
I also recommend you look up the function tolower
which will lower-case a character, meaning you need to do less comparisons which will make this code much easier to read and maintain. Also you might consider using a switch or any array hereand probably writing a helper function.
I guess I just can't stand this code as it is, here's a better version:
int is_vowel(char ch)
{
switch (tolower(ch))
{
case 'a': case 'e': case 'i': case 'o': case 'u':
return 1;
default:
return 0;
}
}
And then make your if statement:
if (is_vowel(string[i]) && is_vowel(string[i+1]))
count++;
See, much cleaner and easier to read, don't you think?