#includeusing namespace std;int main(){ char text[50]; int upper=0,lower=0,digital=0,space=0,other=0,i; cin.getline(text,50)for(i=0;text[i]!='\0';i++){ if(text[i]>='A'&&text[i]=<'Z')upper++; else if(text[i]>='a'&&text[i]<='z')lower++; else if(text[i]>='0'&&text[i]<='9')digital++; else if(text[i]==' ')space++; else other++; } cout<<"大写字母有"<<upper<<endl; cout<<"小写字母有"<<lower<<endl; cout<<"数字有"<<digital<<endl; cout<<"空格有"<<space<<endl; cout<<"其他有"<<other<<endl; }
cin.getline(text, 50)之后少了分号
if (text[i] >= 'A' && text[i] =< 'Z') 是<= 不是=<
你题目的解答代码如下:
#include <iostream>
using namespace std;
int main()
{
char text[50];
int upper = 0, lower = 0, digital = 0, space = 0, other = 0, i;
cin.getline(text, 50);//之后少了分号
for (i = 0; text[i] != '\0'; i++)
{
if (text[i] >= 'A' && text[i] <= 'Z') //是<= 不是=<
upper++;
else if (text[i] >= 'a' && text[i] <= 'z')
lower++;
else if (text[i] >= '0' && text[i] <= '9')
digital++;
else if (text[i] == ' ')
space++;
else
other++;
}
cout << "大写字母有" << upper << endl;
cout << "小写字母有" << lower << endl;
cout << "数字有" << digital << endl;
cout << "空格有" << space << endl;
cout << "其他有" << other << endl;
}
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!