Count the number of vowel, Consonant and so on

#include <iostream>
using namespace std;

int main(){
    char line[150];
    int vowel,consonant,number,space;
    vowel = consonant = number = space = 0;

    cout<<"Enter a Sentence"<<endl;
    gets(line);
    
    for(int i=0; line[i] != '\0'; i++){
        line[i] = tolower(line[i]);

        if(line[i] == 'a' || line[i] == 'e' || line[i] == 'i' || line[i] == 'o' || line[i] == 'u')
        {
            ++vowel;
        }
        else if((line[i] > 'a' && line[i] < 'z')){
            ++consonant;
        }
        else if(line[i]> '0' && line[i]< '9'){
            ++number;
        }
        else if(line[i] == ' '){
            ++space;
        }
    }

    cout<<"Vowel is = "<<vowel<<endl;
    cout<<"Consonant is = "<<consonant<<endl;
    cout<<"Number is = "<<number<<endl;
    cout<<"Space is = "<<space<<endl;
    return 0;
}

    Leave a Reply

    Your email address will not be published.

    Need Help?