in perl, check each word for a vowel. Exit with false if any word is without a vowel.
sub $has_vowel {
$tf = 1;
foreach $word (split " ",$line) {
next if $word =~ /[aeiou]/;
$tf = 0;
last;
}
return $tf;
}
I need to write a function that can determine if each word in a given string contains a vowel. If each word contains a vowel, the function shall return true, if not, the function shall return false.
My prefered language is C++, but if you want to explain in a similar language (C, Java, C#, ...), that's fine too! Just please don't do Python.
i.e., "hello there man" ---> TRUE, "hello there mrn" ---> FALSE
Thanks in advance to anyone willing to help :)
2 answers
not quite. The call would be
has_vowel("check this strng fr vwels")
sub has_vowel {
$tf = 1;
foreach $word (split) {
next if $word =~ /[aeiou]/;
$tf = 0;
last;
}
return $tf;
}
has_vowel("check this strng fr vwels")
sub has_vowel {
$tf = 1;
foreach $word (split) {
next if $word =~ /[aeiou]/;
$tf = 0;
last;
}
return $tf;
}