Vowels counting not working anymore

This code was working for me 30 minutes ago, but all of a sudden it started to return 0's and 1's. It's supposed to count how many vowels does the string I input have.

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
  #include <iostream>
//#include <cstring>
using namespace std;

const int NUM = 51;

int countVowels(char * , char *  );

int main()
{
	const int NUM=51;
	char vowel[NUM];
	char comp[]="aeiou";
	
	
	 
	 cout<<"Enter a string: ";
	 cin.getline(vowel, NUM);
	 
	 cout<<countVowels(vowel, comp);
	 cout<<endl;
	 
	 return 0;
}

int countVowels(char * strPtr, char *  ch)
{
	int count=0;
	while(*strPtr != '\0')
	{
		if(*strPtr == *ch)
			count++;
			strPtr++;
		
	}
	return count;
}


Is there anything wrong?
You're not checking each letter of the string against all your possible vowels.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int countVowels(char * strPtr)
{
    int count=0;  //running total of vowels found
    char vowels[5] = {'a','e','i','o','u'};  //list of all our vowels
    while(*strPtr != '\0') //while we haven't reached the end of the string...
    {
        for(int i = 0; i < 5; ++i) //loop over our list of vowels
        {
            if(*strPtr == vowels[i])  //if the current character in the string equals a vowel...
                count++;   //increment our vowel count by one
        }
        strPtr++;  //now that we've looked and compared to each vowel, move to the next char in the string
    }
    //end of while loop, we've reached the end of the string

    return count;  //return how many vowels we counted
}
That fixed it, thanks for the help!
Topic archived. No new replies allowed.