为什么不能实现啊?最后显示的都为0!!!!!!!

DTCPHQ 2008-04-17 08:30:44
#include <iostream>
using namespace std;
int main ()
{
char a[100];
int i=0;
int C=0,c=0,n=0,o=0;
bool condition = true;
while(condition)
{
if(a[i]=getchar()=='\n')
{
condition = false;
}
i++;
}
for(int j=0;j !='\0';j++)
{
if(a[j]<=90 && a[j]>=65)
{
C++;
}
else if(a[j]<=122 && a[j]>=97)
{
c++;
}
else if(a[j]<=57 && a[j]>=48)
{
n++;
}
else
o++;
}
cout<<"there are "<<C<<" Capitals"<<endl;
cout<<"there are "<<c<<" small letters"<<endl;
cout<<"there are "<<n<<" numbers"<<endl;
cout<<"there are "<<o<<" others"<<endl;
return 0;
}
...全文
99 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
DTCPHQ 2008-04-17
  • 打赏
  • 举报
回复
输入一串字符,找出整数个人,大写字母个数,小写个数及其他!
不想低调 2008-04-17
  • 打赏
  • 举报
回复
lz要实现什么 ?
c_spark 2008-04-17
  • 打赏
  • 举报
回复
程序帮你改了一下
#include <iostream> 
#include <string>
using namespace std;
int main ()
{
//char a[100];
string a;
int i=0;
int C=0,c=0,n=0,o=0;
bool condition = true;
/*while(condition)
{
if((a[i]=getchar())=='\n') //只能读入字符...
{
condition = false;
}
i++;
}*/
getline(cin,a);
for(int j=0;a[j] !='\0';j++) //j->a[j]这里要判断的是字符串中的a[i]是否'\0'
{
if(a[j] <=90 && a[j]>=65)
{
C++;
}
else if(a[j] <=122 && a[j]>=97)
{
c++;
}
else if(a[j] <=57 && a[j]>=48)
{
n++;
}
else
o++;
}
cout <<"there are " <<C <<" Capitals" <<endl;
cout <<"there are " <<c <<" small letters" <<endl;
cout <<"there are " <<n <<" numbers" <<endl;
cout <<"there are " <<o <<" others" <<endl;
return 0;
}
baihacker 2008-04-17
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
int main ()
{
char a[100];
int i=0;
int C=0,c=0,n=0,o=0;
bool condition = true;
while(condition)
{
if((a[i]=getchar())=='\n') //这里有问题
{
condition = false;
}
i++;
}
for(int j=0;a[j]!='\n';j++) //条件
{
if(a[j] <=90 && a[j]>=65)
{
C++;
}
else if(a[j] <=122 && a[j]>=97)
{
c++;
}
else if(a[j] <=57 && a[j]>=48)
{
n++;
}
else
o++;
}
cout <<"there are " <<C <<" Capitals" <<endl;
cout <<"there are " <<c <<" small letters" <<endl;
cout <<"there are " <<n <<" numbers" <<endl;
cout <<"there are " <<o <<" others" <<endl;
return 0;
}

baihacker 2008-04-17
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
int main ()
{
char a[100];
int i=0;
int C=0,c=0,n=0,o=0;
bool condition = true;
while(condition)
{
if((a[i]=getchar())=='\n') //这里有问题
{
condition = false;
}
i++;
}
for(int j=0;a[j]!='\n';j++) //条件
{
if(a[j] <=90 && a[j]>=65)
{
C++;
}
else if(a[j] <=122 && a[j]>=97)
{
c++;
}
else if(a[j] <=57 && a[j]>=48)
{
n++;
}
else
o++;
}
cout <<"there are " <<C <<" Capitals" <<endl;
cout <<"there are " <<c <<" small letters" <<endl;
cout <<"there are " <<n <<" numbers" <<endl;
cout <<"there are " <<o <<" others" <<endl;
return 0;
}

baihacker 2008-04-17
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
int main ()
{
char a[100];
int i=0;
int C=0,c=0,n=0,o=0;
bool condition = true;
while(condition)
{
if((a[i]=getchar())=='\n') //这里有问题
{
condition = false;
}
i++;
}
for(int j=0;a[j]!='\n';j++) //条件
{
if(a[j] <=90 && a[j]>=65)
{
C++;
}
else if(a[j] <=122 && a[j]>=97)
{
c++;
}
else if(a[j] <=57 && a[j]>=48)
{
n++;
}
else
o++;
}
cout <<"there are " <<C <<" Capitals" <<endl;
cout <<"there are " <<c <<" small letters" <<endl;
cout <<"there are " <<n <<" numbers" <<endl;
cout <<"there are " <<o <<" others" <<endl;
return 0;
}

相关推荐
发帖
C++ 语言

6.3w+

社区成员

C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
帖子事件
创建了帖子
2008-04-17 08:30
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下