Guys I'm getting a 0 every time I run this program. I'm not sure if only the base case is getting executed or if I am just missing something. Can anyone tell me why anytime I run this my output is always 0?
//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)
{
//call recursive function, point to rightmost digit
return bin2dec(num,0);
}
int bin2dec(int num , int pl)
{
if(num == 0)
return 0;
elsereturn num % 10 * int(pow(2.0,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) << endl;
cout << "Another?(Y/N) : ";
cin >> again;
}while(toupper(again)=='Y');
}//endmain