Functionally they are the same, but you may find a switch/case structure easier to write (and possibly read) than the if statement with many conditions ORed together:
Code:
switch (phrase[index])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
++vowel;
}
Also, it probably does not make much of a difference, but we typically pass objects of class types by reference. In this case, the string should be passed by const reference since it is not modified:
Code:
int vowels(const string& phrase)
{
// ...
Another thing: again, it does not make a real difference here, but the length() member function of std::string returns a std::string::size_type, not an int. By default, std::string::size_type is defined to a type that resolves to size_t, and size_t in turn is typically defined as unsigned int. As such, it is better to write:
Code:
for ( string::size_type index = 0; index < phrase.length(); index++)