I cant figure out what i did wrong.. please help!!

Using what you have learned about value-returning functions, create one of your own named isVowel that returns the value true if a character is a vowel and otherwise returns false. Also write a program to test your function.


my code:
#include<iostream>
#include<string>

bool isvowel(char x )
{
if ((x =='a' )||(x == 'u')||(x=='e')||(x=='o')||(x== 'i') )

return true ;
else
return false ;

}

int main()
{

std::string testString("isVowel");
int numVowels(0);

for(int i=0;i < (int)testString.size();++i)
{
char charToTest = testString.at(i);

if(true == isvowel(charToTest))
{
numVowels++;
}
}

std::cout << "Number of vowels in '" << testString << "': " << numVowels;
system("pause");
return 0;
}

what did i do wrong??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <string>
#include <cctype>

bool is_vowel( char c )
{
    c = std::tolower(c) ; // if c is an upper-case letter, convert it to lower-case
    return ( c =='a' ) || ( c == 'u') || ( c == 'e' ) || ( c =='o' ) || ( c == 'i' ) ;
}

int main()
{
    const std::string str = "IsVowel" ;

    {
        int num_vowels = 0 ;
        
        for( char c : str ) // range-based loop (for each character c in string str)
        {
            if( is_vowel(c) ) ++num_vowels ;
        }
        
        // outside the loop
        std::cout << "Number of vowels in '" << str << "': " << num_vowels << '\n' ;
    }

    {
        int num_vowels = 0 ;
        
        for( std::size_t i = 0 ; i < str.size() ; ++i ) // classical for loop
        {
            if( is_vowel( str[i] ) ) ++num_vowels ;
        }

        // outside the loop
        std::cout << "Number of vowels in '" << str << "': " << num_vowels << '\n' ;
    }
}

http://coliru.stacked-crooked.com/a/376a5faa4853e4c3
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) What makes you think something's wrong?
there is a parse error before both for statements and i cant see my output
I only see one for statement in your code. What are the actual error messages you're getting?
Topic archived. No new replies allowed.