'Space and other character does gets counted
Every single time I run this program I get the number of vowels and consonants only gets counted the number of spaces and any other special characters are not counted I can't seem to figure out what is wrong in my code. Does anybody have the solution to this?
void vowel_consonant(char *c)
{
int i,vcount,ccount,scount,ocount;
vcount=ccount=scount=ocount=0;
for (i=0;c[i]!='\0';i++)
{
if((c[i]=='a'||c[i]=='e'||c[i]=='i'||c[i]=='o'||c[i]=='u')||(c[i]=='A'||c[i]=='E'||c[i]=='I'||c[i]=='O'||c[i]=='U'))
vcount++;
else if((c[i]>=65 || c[i]<=90) && (c[i]>=97 || c[i]<=122))
ccount++;
else if(c[i]==' ')
scount++;
else
ocount++;
}
cout<<"Number of vowels:"<<vcount<<endl;
cout<<"Number of consonant:"<<ccount<<endl;
cout<<"Number of space:"<<scount<<endl;
cout<<"Number of extra:"<<ocount<<endl;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
