等5类字符出现的次数 例如 若输入:I am 20 years old! 则5类字符出现的次数分别是1、10、2、4、1
下面是我写出的程序 不知道哪里错了
#include <iostream.h>
void main()
{
char ch;
int num=0,d=0,x=0,space=0,other=0;
while((ch=cin.get())!='\n')
if(ch>='A'&&ch<='Z')
d++;
else if (ch>='a'&&ch<='z')
x++;
else if(ch>='0'&&ch<='9')
num++;
else if(ch=' ')
space++;
else other++;
cout<<"d="<<d<<endl;
cout<<"x="<<x<<endl;
cout<<"num="<<num<<endl;
cout<<"space="<<space<<endl;
cout<<"other="<<other<<endl;
}
这个过程运行完之后得如下
d=1 x=10 num=2 space=5 other=0 里面的空格字符数 和其他字符数都不对不知道为什么
哪位能帮忙解答一下啊??很急很急 万分感谢
不好意思还是有几个问题不懂
1。数字的话不包括0吗?如果是1-9的话那如果有0怎么办啊?
2. 题里的是大小写字母各自的字符数是多少 如果用||的话应该只能输出字母的字符 不能区分大小写了 是吗?
3.我上面那个程序里面也是把other放在最后 可是为什么的出来就是0呢?还有我算出来的空格数比正确的多一个 为什么
麻烦你了谢谢