I need to return the last vowel (uppercase or lowercase) in a given string and return '!' if there aren't any vowels in the string.
The code I wrote works but only if the string ends with a vowel. If it doesn't end with a vowel it always returns a '!'.
How can I fix this?
char lastVowel(string s){
char vowel = ' ';
for(int i = 0; i < s.size(); ++i){
if(s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U' ||
s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u'){
vowel = s[i];
}else{
vowel = '!';
}
}
return vowel;
}