读书人

一个关于单纯词计数的程序

发布时间: 2013-10-07 19:41:22 作者: rapoo

一个关于单词计数的程序


#include<iostream>
#include<string>
#include<cstring>
#include<cctype>
using namespace std;
const int size=0;

int main()
{
char ch[size];
int yuan_count=0;
int fu_count=0;
int count=0;
cout<<"enter words(q to quit):"<<endl;
cin>>ch;
while(strcmp("q",ch))
{
if(isalpha(ch[0]))
{
if(ch[0]=='a'||ch[0]=='e'||ch[0]=='i'||ch[0]=='o'||ch[0]=='u')
yuan_count++;
else
fu_count++;
}
else
count++;
cin>>ch;
}
cout<<yuan_count<<" words beginning with vowels"<<endl;
cout<<fu_count<<" wrods beginning with consonants"<<endl;
cout<<count<<" others"<<endl;
return 0;
}


我用上述程序来统计输入的词语中的元音 辅音 以及 其他的书目,但是每次元音字母开头的单词的数目 都是个莫名其妙的数目,不知道为什么 求大神教导! c++
[解决办法]
你把6行的size换个数
数组长度不能0
我这试了没错

读书人网 >C++

热点推荐