u

Thursday 7 June 2012

C++ Program to display Consonants and Vowels output from an entered string

C++ Program to display  Consonants and Vowels output from an entered string


#include <iostream.h>
#include <string.h>
#include <conio.h>
void main()


    {   clrscr();
    int consonant =0;
    int vowel =0;
    int k =0;
    char response[20];

    cout<<"Please enter a word "<<endl;
    cin>>response;
    while (k<20 && response[k] != '\0')


    {
        switch(response [k])


        {
        case 'a':
        case 'A':
        case 'e':
        case 'E':
        case 'i':
        case 'I':
        case 'o':
        case 'O':
        case 'u':
        case 'U':
            ++vowel;
            break;
        default:
            ++consonant;
            break;
        }
        ++k;
    }
    cout<<"There are "<<vowel<<" vowel(s) in your string"<<endl;
    cout<<"There are "<<consonant<<" consonant(s)in your string"<<endl;
    cout<<"Press any key to continue"<<endl;
    getch();
    }

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More