63,579
社区成员




#include "stdafx.h"
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"enter words (q to quit):\n";
string words; //我试过用char数组
int vowels = 0;
int other = 0;
int consonant = 0;
char ch;
cin>>words; //但为什么用char数组时循环不能判断为"q"的输入
while (words!="q")
{
switch (words[0])
{
case 'a':vowels++;break;
case 'e':vowels++;break;
case 'i':vowels++;break;
case 'o':vowels++;break;
case 'u':vowels++;break;
}
if (isalpha(words[0]))
{
if (words[0]!= 'a'&&words[0]!= 'e'&&words[0]!= 'i'&&words[0]!= 'o'&&words[0]!= 'u')
consonant++;
}
else
other++;
cin>>words;
}
cout<<endl<<vowels<<" words beginning with vowels\n";
cout<<consonant<<" words beginning with consonant\n";
cout<<other<<" other.\n";
return 0;
}
while (words!=string("q"))
呵呵看错了
char ch;
cin>>words; //但为什么用char数组时循环不能判断为"q"的输入
while (words!="q")///? 'q'