how to count chars?

So i'm trying to write a program that counts vowels and tells the user how many vowels they entered and how many consonants they entered. problem is my answer returns some weird stuff.

side note : I have to use char can't be a string.
side note 2: By counting chars I mean abc equals 3, abcd = 4, ... but I want this in vowels and consonants.

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  //Programed by : Jackelinblack
//Program that uses a value returining function to let the user know
//if a certain charecter is a vowel and output how many vowels and non vowels
// have been entered.
#include <iostream>
using namespace std;
// function prototype
bool issvowel (char);
int main() {
    
    char vowels , notVowel;
    char v = 0 , n = 0;
    char isvowel;
    cout << "Enter a character " << endl;
    //cin >> vowels;
    
    isvowel = issvowel(isvowel);
    
        while (issvowel (isvowel)){
        
        if (isvowel == true)
            {
            cout << "Enter a vowel " << endl;
            cin >> vowels;
                v++;
            }
       //Don't think the code even reaches this point.
        else
        {
            cout << "Enter another character " << endl;
            cin >> notVowel;
            n++;
        }
    cout << "you entered " << v << " vowels and " << n << " consonates " << endl;
    }
    
    
    return 0;
}
bool issvowel (char isvowel)
{
    
    if (isvowel == 'a' || isvowel == 'e' || isvowel == 'i' || isvowel == 'o' || isvowel == 'u')
    {
        isvowel = true;
    return isvowel;
    }
    else{
        isvowel = false;
    
    return isvowel;
    }
}
Last edited on
Pay attention to details. For example:

On line 17 you pass an uninitialized bool into functio that expects a char.

On line 45 you assign true to a char variable.

On line 46 you return a function pointer when you should return a bool.
ok so i fixed what you mentioned plus a few more things.
is there anything else that is causing my code not to work?
Last edited on
Please explain lines 12, 17, 19, 24, 31, 45, and 49.

PS. Indentation can make scopes easier to see. For example, what is within the while-loop?
Topic archived. No new replies allowed.