6.7
#include<iostream> #include<cctype> using namespace std; void main67() { const int Size=10; int vowels=0; //存储个数 int consonants=0; int other=0; cout<<"Enter words (q to quit)"<<endl; char temp[Size]; char ch='0'; char t; //读取数组内单个字符 do{ //while(ch!='13'&&ch!='\n') //{ cin>>temp; cout<<temp<<" "<<endl; t=temp[0]; //int j=0; //while(t!='\0') //判断元音开头 //{ 这里我默认输入的都是单词或者数字,即不会出现如 aag125sa这类的输入 if(!isalpha(t)) other++; else if(t=='a'||t=='e'||t=='i'||t=='o'||t=='u') vowels++; else consonants++; //} if(temp[0]=='q'&&strlen(temp)==1) //判断是否为q至关重要的一步 break; //} /** cout<<"vowels="<<vowels<<endl; cout<<"consonants="<<consonants<<endl; cout<<"other="<<other<<endl; cout<<"ch== "<<ch<<endl; */ }while(true); cout<<vowels<<" words beginning with vowels"<<endl; cout<<consonants<<" words beinning with consonants"<<endl; cout<<other<<" others"<<endl; system("pause"); }
——————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:https://www.royalchen.com/
author:royalchen
Email:royalchen@royalchen.com
———————————————————————————————————————————————————