I'm very very new so I'm sorry if this is an obvious question.
I'm writing a function trying to find gibberish words(ones that don't have vowels) but I don't know how to check for every word in the string. I have the following code
1 2 3 4 5 6 7 8 9 10 11
bool isGibberishWord(string e)
{ string a;
for (size_t k=0; k <= e.size(); k++)
{
a=e.substr(k,3);
if (a.find_first_of("aeiouAEIOU")== -1) break;
bool b;
b=true;
}
return b;
}
but the b in the braces doesn't relate to the one outside the braces.
I have this problem a lot. I don't know how to check more than one thing by one loop.
can someone help me please?
Inside the for you can check e[k] which is a single character in the string. If it is a vowel, return false, if not continue the loop. At the end return true ( no vowels were found )
example:
1 2 3 4 5 6 7 8 9 10 11 12
bool isGibberishWord(string e)
{
for (size_t k=0; k <= e.size(); k++)
{
switch ( tolower ( e[k] ) ) // less checking with this
{
case'a': case'e': case'i': case'o': case'u':
returnfalse; // you found a vowel, no gibberish
}
}
returntrue; // you didn't find a vowel
}