i dont knw why i am not getting the right ans
can someone help?
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
int sum=0;
string val;
cout<<"enter a binary number:"<<endl;
cin>>val;
for(int i=0;i<val.size();i++)
{
cout<<val[i];
}
for(int i=1;i<val.size();i++)
{
int x = val.size();
sum+=val[x-i]*pow(2.0,i-1);
}
cout<<sum;
return 0;
}