Your Task:
Write a program that accepts a word as an input, and outputs
the number of different consonants (b,d,f,g,h...) in the word.
The word consists of small and capital alphabets only.
For example, the output for the word "Lolz" is 2 because
there are 2 different consonants ('l' and 'z')
Sample run 1 :
Enter a word -> Lolz
Number of different consonants : 2
Sample run 2 :
Enter a word -> MamMaMia
Number of different consonants : 1
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
char cons;
int consonantCount = 0;
string word;
cout << "Please enter a word which consists only small and capital alphabets. " << endl;
getline(cin, word);
for ( int pos = 0; pos < word.length(); pos++)
{
cons = toupper (word[pos]);
switch(cons)
{ case 'B' :
case 'C' :
case 'D' :
case 'F' :
case 'G' :
case 'H' :
case 'J' :
case 'K' :
case 'L' :
case 'M' :
case 'N' :
case 'P' :
case 'Q' :
case 'R' :
case 'S' :
case 'T' :
case 'V' :
case 'W' :
case 'X' :
case 'Y' :
case 'Z' : consonantCount++;
}
}
cout << "Number of different consonant= " << consonantCount << endl;
system ("pause");
return 0;
}