Count vowels from user input string characters

I came across a few other entries to help me formulate this program.

However, the benefit of the following program is that it implements a user-defined function to count the number of vowels from a prompted user input. Therefore, it has a practical side to it :)

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
#include <iostream>
#include <string>

using namespace std;

int VowelCount (string Input);//funtion prototype

int main()
{
	string input;

	cout << "Please enter a sequence of characters: " ;
	cin >> input;//gather user input

	//cout << input.size();//a debugging technique to test values

	cout << endl << endl << "Number of vowels: " 
		<< VowelCount(input) << endl << endl;//function call within output

	return 0;
}//end main


int VowelCount(string entry)
{
	int limit = entry.size();//used in the for loop
	char tmp;
	int vowelCounter = 0;//used as the return value later

	for (int i = 0; i < limit; i++)
	{
		tmp = toupper(entry[i]);//limits the amount of cases needed
		switch(tmp)//cycles through each character in the string
		{		
			case 'A' :
			case 'E' :
			case 'I' :
			case 'O' :
			case 'U' :
				vowelCounter++;
				break;
			default:
				break;//you could potentially set up other counters too
		}//end switch

	}//end for loop

	return vowelCounter;// value is returned to the main function
	
}//end isVowel 
Topic archived. No new replies allowed.