主题:[讨论]谁能帮我找错?
#include<iostream.h>
void main()
{
char ch;
int nother(0),ndigit[10];
for(int i=0;i<10;i++)
ndigit[i]=0;
cout<<"Input some characters:\n";
cin>>ch;
while(ch!='#')
{
switch(ch)
{
case'0':
case'1':
case'2':
case'3':
case'4':
case'5':
case'6':
case'7':
case'8':
case'9':++ndigit[ch-'0'];
break;
default:++nother;
}
cin>>ch;
}
cout<<"digit=";
for(i=0;i<10;i++)
cout<<ndigit[i]<<'';
cout<<"\nother="<<nother<<endl:
}
编译结果在附件的图中
void main()
{
char ch;
int nother(0),ndigit[10];
for(int i=0;i<10;i++)
ndigit[i]=0;
cout<<"Input some characters:\n";
cin>>ch;
while(ch!='#')
{
switch(ch)
{
case'0':
case'1':
case'2':
case'3':
case'4':
case'5':
case'6':
case'7':
case'8':
case'9':++ndigit[ch-'0'];
break;
default:++nother;
}
cin>>ch;
}
cout<<"digit=";
for(i=0;i<10;i++)
cout<<ndigit[i]<<'';
cout<<"\nother="<<nother<<endl:
}
编译结果在附件的图中