/*文件名称:
*作者:
*完成日期:2013年 12月
*版本号:v1.0
*对任务及求解:
*输入描述: 一行字符
*问题描述: 用getchar()依次判断
*程序输出:
*问题分析:
*算法设计:
*/
#include <iostream>
using namespace std;
int main()
{
char c;
int letter1=0,letter2=0,numble=0,other=0,A=0;
cout<<"请任意输入一行字符:";
while((c=getchar())!='\n') //判断是否按了Emter键。
{
if(c>='a'&&c<='z')
letter1++;
else if(c>='A'&&c<='Z')
{
letter2++;
if(c=='A')
{A++;}
}
else if(c>'0'&&c<='9') //要带上' '但引号不然会出错认为不是十进制的数字,而是某个字母
numble++;
else
other++;
}
cout<<"字符中有小写字母"<<letter1<<"个,字符中有大写字母"<<letter2<<"个,大写A有"<<A<<"个,有数字"<<numble<<"个,其他字符有"<<other<<"个。";
cout<<endl;
return 0;
}
