马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 yzyou521 于 2016-2-22 15:02 编辑
如题:编译没有问题,运行结果是错误的void GetNumber(char CharNum[])
{
int i=0;
int Figure;
int HexDencimalNumber[10];
//开始十六进制获取数据
cout<<"Please input a hexdecimal number."<<endl;
cout<<"Then ending with 'H' or 'h'.:";
cin>>CharNum;
cout<<"Hexdicimal list like this:"<<endl;
while(CharNum[i]!='h' && CharNum[i]!='H')
{
//cout<<CharNum[i]<<endl; 临时测试语句
if(CharNum[i]='0')
{
HexDencimalNumber[i]=0;
}
if(CharNum[i]=='1')
{
HexDencimalNumber[i]=1;
}
if(CharNum[i]=='2')
{
HexDencimalNumber[i]=2;
}
if(CharNum[i]=='3')
{
HexDencimalNumber[i]=3;
}
if(CharNum[i]=='4')
{
HexDencimalNumber[i]=4;
}
if(CharNum[i]=='5')
{
HexDencimalNumber[i]=5;
}
if(CharNum[i]=='6')
{
HexDencimalNumber[i]=6;
}
if(CharNum[i]=='7')
{
HexDencimalNumber[i]=7;
}
if(CharNum[i]=='8')
{
HexDencimalNumber[i]=8;
}
if(CharNum[i]=='9')
{
HexDencimalNumber[i]=9;
}
if(CharNum[i]=='a'||CharNum[i]=='A')
{
HexDencimalNumber[i]=10;
}
if(CharNum[i]=='b'||CharNum[i]=='B')
{
HexDencimalNumber[i]=11;
}
if(CharNum[i]=='c'||CharNum[i]=='C')
{
HexDencimalNumber[i]=12;
}
if(CharNum[i]=='d'||CharNum[i]=='D')
{
HexDencimalNumber[i]=13;
}
if(CharNum[i]=='e'||CharNum[i]=='E')
{
HexDencimalNumber[i]=14;
}
if(CharNum[i]=='f'||CharNum[i]=='F')
{
HexDencimalNumber[i]=15;
}
i++;
}
Figure=i;
cout<<Figure<<endl;//test function输出正确
cout<<"Change to number is:"<<endl;
for(i=0;i<Figure;i++)
{
cout<<HexDencimalNumber[i]<<endl; //此处的输出结果是错误的
}
}
|