Hi al...I am a total c++ beginner...I need ur help plz...I am making a program which asks the user to input a binary number and displayz the binary number converted to decimal number using a function.

The code which i wrote is below:

#include<iostream.h>

#include<math.h>

int bin2dec(int n)

{

int k=0, sum=0,x;

while(n>0)

{

x=n%10;

sum+=x*pow(2,k++);

n/=10;

}

return sum;

}

void main()

{

int n,dec;

cout<<"Enter any binary number"<<endl;

cin>>n;

cout<<"The binary number converted to decimalform= "<<dec=bin2dec(n);

cout<<endl;

}