loops

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?
Last edited on
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':
                 return false; // you found a vowel, no gibberish
        }
    }
    return true; // you didn't find a vowel
}

Last edited on
What dose "string e" include? Just one word or some words?
If the "string e" is a word, my code like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool isGibberishWord(string e)
{
    char a[] = "aeiouAEIOU";
    bool b = true;
    
    for (unsigned int k=0;k<strlen(a);k++)
    {
        if (e.find(a[k]) != 0) 
        {
            b = false;
            break;
        }
    }
    return b;
}

but the b in the braces doesn't relate to the one outside the braces

It's about the scope of variables:
http://www.cplusplus.com/doc/tutorial/variables/
Topic archived. No new replies allowed.