Hey guys! I'm trying to write a recursive function to take a number in binary form and change it to decimal. As of now I am having the dumbest problem. I can't seem to take 2 to a variable power. This is probably something so basic but I'm drawing a blank. (Oh, and I haven't written a clause to prevent any numbers outside of 0 &1 yet so please ignore that little part).
As of now, I can't even test if I have the right idea for my recursive function because I can't compile due to some issue with taking 2 to a particular power.
Here is my recursive function called binary:
int binary(const int data[], int position)
{
int result;
if(position==0)
{
result=data[position]*pow(2,position);
}
else
{
result=(data[position]*pow(2,position))+binary(data, position-1);
}
return result;
}
Let me know if you need my entire code! Thanks in advance for any suggestions. Oh, and I do have the cmath header in there so I know that much isn't the problem...:yawn:
And this is the error message I get:
D:\MyPrograms\Recursion>g++ Num4.cpp -o test4.exe
Num4.cpp: In function `int binary(const int*, int)':
Num4.cpp:44: error: call of overloaded `pow(int, int&)' is ambiguous
D:/mingw32_snapshot_02-10-2009/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../in
clude/math.h:156: note: candidates are: double pow(double, double)
D:/mingw32_snapshot_02-10-2009/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../in
clude/c++/3.4.5/cmath:361: note: long double std::pow(long doubl
...and it goes on...