Hello everyone I am here about a question on an assignment of mine. The question is due tomorrow so please correct my mistake rather than dropping hints. I normally would greatly appreciate it but in this case I am in a bit of a hurry and I promise that I will study my mistake as to where I went wrong.
The questions asks to enter a sentence and in the end be able to portray the amount of vowels, words, upper case letters and lower case letters. Also I must use the part of the vowels in a function using the library <cctype>. I was able to compile all of the other requests except the vowels which Im unsure why. There are no errors in the program but it portrays in the output that there are 0 vowels.
Here is my program
void VowelSearch (char c, int V);
using namespace std;
int main ()
int Ul = 0, Ll = 0, W = 1, V = 0;
cout << "I can cout the number of upper case, lower case, vowels and words\n";
cout << "Please enter a sentence: ";
while(cin.get(c), c != '\n')
VowelSearch (c, V);
cout << " No. of upper case letters..........." << Ul << endl;
cout << " No. of lower case letters............" << Ll << endl;
cout << " No. of words............." << W << endl;
cout << " No. of vowels............" << V << endl;
void VowelSearch (char c, int V)
case 'a': case 'e':case 'i':case 'o':case 'u':
case 'A': case 'E':case 'I':case 'O':case 'U':
First, please you code tags: select all your code and click the '<>' button in the Format options. Make sure that the code is indented properly, too: it makes it easier for us to read and tell you what you have done wrong.
Now, to your question. It makes it easier on yourself (and everyone around you) if you use meaningful names. If that means that your variable names are more than one or two letters long, so be it. But at any rate, your error could be your if statement in VowelSearch: you have a semicolon on the end of your if statement, which means that the switch is executed regardless of whether or not it is a vowel. Also, you need to pass 'V' by reference to increase it as you have done here, otherwise the temporary copy owned by the function will be modified instead, which would lead to no effect in your main function. What would probably better, though, is to instead use something like an isVowel function, which returns true or false, and then increase the 'V' variable by one in that case instead.