Mister C:
I tried your statment for the base case:
Code:
if (phrase[0] == "")
return 0;
I receive two errors while compiling!
c:\Documents and Settings\...\T3Q24_Vowels.cpp(29): error C2040: '==' : 'int' differs in levels of indirection from 'const char [1]'
c:\Documents and Settings\...\T3Q24_Vowels.cpp(29): error C2446: '==' : no conversion from 'const char *' to 'int'
so, I reverted back to the phrase.empty() becasue it not only doesn't have vowels it doesn't have anything. phrase.empty() works as a base case, but the rest doesn't.
However I changed the string to a pass by reference and changed the OR list of vowel checks to case statement and I now get just one vowel no matter what the string contains. I also changed the return to use the phrase.substr() to knock off the first character in the string, or that was my intent.
the new code is:
Code:
int vowels(const string& phrase)
{
if (phrase.empty())
return 0;
else
switch(phrase[0])
{
case 'a': case 'A':
case 'e': case 'E':
case 'i': case 'I':
case 'o': case 'O':
case 'u': case 'U':
return vowels(phrase) + vowels(phrase.substr(1, phrase.size()));
}
}
I appreciate the help and am trying all the suggestions.
Thanks!