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 54 55 56 57 58
|
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
void countVowels(char ch, int& aCt, int& eCt, int& iCt, int& oCt, int& uCt);
int main()
{
string inputString;
int aCount = 0;
int eCount = 0;
int iCount = 0;
int oCount = 0;
int uCount = 0;
cout << "Enter a string" << endl;
getline(cin, inputString);
for (unsigned int i = 0; i < inputString.length(); i++)
countVowels(inputString.at(i), aCount, eCount,
iCount, oCount, uCount);
cout << "The number of a's: " << aCount << endl;
cout << "The number of e's: " << aCount << endl;
cout << "The number of i's: " << aCount << endl;
cout << "The number of o's: " << aCount << endl;
cout << "The number of u's: " << aCount << endl;
system("pause");
return 0;
}
void countVowels(char ch, int & aCt, int & eCt, int & iCt, int & oCt, int & uCt)
{
ch = tolower(ch);
switch (ch)
{
case 'a':
aCt++;
break;
case 'e':
eCt++;
break;
case 'i':
iCt++;
break;
case 'o':
oCt++;
break;
case 'u':
uCt++;
break;
}
}
|