菜鸟问一个十进制向二进制的转换问题
#include"iostream.h"#include"math.h"
struct Stack{
float *data;
int size;
int memNum;
}
initStack(Stack &s,int size)
{
s.data=new float[size];
if(s.data==NULL)
return 0;
s.memNum=0;
s.size=size;
return 1;
}
float popStack(Stack &s,int &num)
{
if(s.memNum==0)
return 0;
num=s.data[--memNum];
return 1;
}
float pushStack(Stack &s,float mem)
{
if(s.memNum==s.size)
return 0;
s.data[memNum++]=mem;
return 1;
}
float decTobina(float n,Stack s)
{
while(n!=0)
{if(int(n%2)==0)
pushStack(s,0);
pushStack(s,1);
n=n/2;
return 1;
}
void main()
{
int i;
float a[50],*num[50];
Stack newstack;
initStack(newstack,32);
for(i=0;i<50;i++)
cin>>a[i];
for(i=0;i<50;i++)
{
decTobina(a[i],newstack);
popStack(newstack,num[i]);
}
for(i=0;i<50;i++)
cout<<a[i]<<"-->"<<num[i]<<endl;
}
运行时出错如下:
--------------------Configuration: 十二转换 - Win32 Debug--------------------
Compiling...
十二转换.cpp
C:\Documents and Settings\Administrator.WWW-99FD08AFD26\桌面\十二转换.cpp(12) : error C2440: 'return' : cannot convert from 'const int' to 'struct Stack'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Documents and Settings\Administrator.WWW-99FD08AFD26\桌面\十二转换.cpp(15) : error C2440: 'return' : cannot convert from 'const int' to 'struct Stack'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Documents and Settings\Administrator.WWW-99FD08AFD26\桌面\十二转换.cpp(21) : error C2065: 'memNum' : undeclared identifier
C:\Documents and Settings\Administrator.WWW-99FD08AFD26\桌面\十二转换.cpp(21) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
C:\Documents and Settings\Administrator.WWW-99FD08AFD26\桌面\十二转换.cpp(34) : error C2296: '%' : illegal, left operand has type 'float'
C:\Documents and Settings\Administrator.WWW-99FD08AFD26\桌面\十二转换.cpp(34) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.
因为刚学C++,所以写的比较幼稚,希望各位大侠帮忙看一下~