Write a program that reads an unspecified number of uppercase or lowercase alphabets, and determines how many of them are vowels and how many are consonants. Enter zero to signify the end of the input.
1
Expert's answer
2016-11-10T10:45:08-0500
// // vowels_consonants.cpp // #include <iostream> #include <cctype> // for isalpha #include <cstring> // for strchr
using namespace std;
int main() { char ch; const char VOWELS[] ={"AaEeIiOoUuYy"}; int num_vowels = 0; int num_consonants = 0; cout << "Enter string of chars (0 to quit); " ; cin.get(ch); while (ch != '0'){ if (isalpha(ch) ){ if ( strchr(VOWELS,ch) != NULL ) ++num_vowels; else ++num_consonants; } cin.get(ch); } cout << "\nNumber of vowels is " << num_vowels <<",number of consonants is " << num_consonants; cout << endl; //keep console window open cout << "\nPress any key to contnue...\n"; cin.get(); cin.get(); return 0; }
Comments
Leave a comment