switch (letter) {
case 'A':
case 'e':
...
cout << "vowel!" << endl;
break;
default:
cout << "consonant!" << endl;
}
instead of:
if (letter == 'A' || letter == 'e' ... ) {
cout << "vowel!" << endl;
}
else {
cout << "consonant!" << endl;
}
It may be more exciting to count the number of vowels in an entire text file. Let's say you have a text file called "gettysburg.txt" which contains the Gettysburg Address. You could do that something like this:
int vowelcounter = 0;
int consonantcounter = 0;
while (cin.get(letter)) {
switch (letter) {
case 'A':
...
++vowelcounter;
break;
default:
++consonantcounter;
}
//now display the results
}
Then run the program like this, so that input comes from the file
gettysburg.txt rather than from you and the keyboard (this is an
example of Input/Output redirection or I/O redirection):
./vowel < gettysburg.txt
This program will actually count too many consonants because it will count spaces, periods, commas, etc as consonants. We will fix that when we get to the alpha-only program.