how to find vowal and consonent of a string in c 2b 2b

Solutions on MaxInterview for how to find vowal and consonent of a string in c 2b 2b by the best coders in the world

showing results for - "how to find vowal and consonent of a string in c 2b 2b"
Naomi
07 Aug 2019
1#include <iostream>
2using namespace std;
3
4int main()
5{
6    char line[150];
7    int vowels, consonants, digits, spaces;
8
9    vowels =  consonants = digits = spaces = 0;
10
11    cout << "Enter a line of string: ";
12    cin.getline(line, 150);
13    for(int i = 0; line[i]!='\0'; ++i)
14    {
15        if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
16           line[i]=='o' || line[i]=='u' || line[i]=='A' ||
17           line[i]=='E' || line[i]=='I' || line[i]=='O' ||
18           line[i]=='U')
19        {
20            ++vowels;
21        }
22        else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
23        {
24            ++consonants;
25        }
26        else if(line[i]>='0' && line[i]<='9')
27        {
28            ++digits;
29        }
30        else if (line[i]==' ')
31        {
32            ++spaces;
33        }
34    }
35
36    cout << "Vowels: " << vowels << endl;
37    cout << "Consonants: " << consonants << endl;
38    cout << "Digits: " << digits << endl;
39    cout << "White spaces: " << spaces << endl;
40
41    return 0;
42}
similar questions