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
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string input;
string result;
int numA, numE, numI, numO, numU, totalVow;
totalVow = 0;
cout << "Enter a string you would like me to count the vowels in: ";
getline(cin, input);
int vowelCount[5] = { numA = 0, numE = 0, numI = 0, numO = 0, numU = 0 };
cout << endl;
string vowelNames[5] = { "A: ", "E: ", "I: ", "O: ", "U: " };
for (int i = 0; i < input.length(); i++) {
if (input[i] = 'a' || 'A') {
numA += 1;
}
else if (input[i] = 'e' || 'E') {
numE += 1;
}
else if (input[i] = 'i' || 'I') {
numI += 1;
}
else if (input[i] = 'o' || 'O') {
numO += 1;
}
else if (input[i] = 'u' || 'U') {
numU += 1;
}
}
totalVow += numA + numE + numI + numO + numU;
cout << "You entered " << totalVow << " vowels!" << endl << "Here are the number of hits per vowel: " << endl;
for (int i = 0; i < 5; i++) {
cout << vowelNames[i] << vowelCount[i] << endl;
}
}
|