Hey guys I know the pow function takes 2 doubles but I static casted it to an int and I still get the error more than one instance matches the arguement list.
What am I doing wrong? Error is on line 22.
//Binary to Decimal
#include <iostream>
#include <cmath>
usingnamespace std;
int bin2dec(int num); //converts binary number to a decimal number
int bin2dec(int num , int pl); //overloaded function
int bin2dec(int num)
{
return bin2dec(num,0);
}
int bin2dec(int num , int pl)
{
if(num==0)
return 0;
elsereturn num % 10 * int(pow(2,pl)) * bin2dec(num/10 , pl+1);
}
int main()
{
char again = 'Y';
do{
cout << "Enter a number in binary (1's and 0's) to see the decimal equivalent: ";
int bin;
cin >> bin;
cout << "The decimal equivalent of " << bin << " is: " << bin2dec(bin);
cout << "Another?(Y/N) : ";
cin >> again;
}while(toupper(again)=='Y');
}//endmain
Before C++11 there was no version of std::pow taking an integer as first argument so it doesn't know if it should use the one taking a float, the one taking a double or the one taking a longdouble as first argument.
To solve this you have two options.
1. Cast the first argument to one of the floating point types.
2. Compile the code in C++11 mode. If your compiler is too old you'll have to upgrade first.