首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

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

2013-10-07 
一个关于单词计数的程序#includeiostream#includestring#includecstring#includecctypeusing name

一个关于单词计数的程序


#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
我这试了没错

热点排行