Write a recursive, bool-valued function, containsVowel, that accepts a string and returns true if the string contains a vowel.
A string contains a vowel if:
The first character of the string is a vowel, or
The rest of the string (beyond the first character) contains a vowel
This is one of the recursion exercises I couldn't get right.
Any suggestions? Thanks!
My code:
bool containsVowel (string s) {
if (s.substr(0,1)=="a") return true;
if (s.substr(0,1)=="e") return true;
if (s.substr(0,1)=="u") return true;
if (s.substr(0,1)=="o") return true;
if (s.substr(0,1)=="i") return true;
containsVowel (s.substr(1,s.length()-1));
}