131 CountingVowelsAndWordsInString (CPP)

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

# include<iostream>

using namespace std;

/*program for count vowels consonant and words

*/
int main()
{
string str="how many words"
int vowels=0,consonant=0,space=0;
for(int i=0;str[i]=!'\0';i++)
{
if(str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' ||
str[i]=='U' || str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' ||
str[i]=='u')
vowels++;
else if(str[i]==' ')
space++;
else
consonant++;
}
cout<<"vowels "<<vowels<<endl;
cout<<"consonant "<<consonant<<endl;
cout<<"words "<<space++<<endl;
return 0;
}

You might also like