Help Out!!!

Can someone help, I wrote this program to convert 2-compliments to decimal but it seems not to be working.

#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int num, j , b, ans, comp[4], i;

cout<<"Enter a 5-bit binary number"<<endl;
cin>>num;
if (i < 5)
{
comp[i]=num % 10;
num = num/10;
i=i + 1 ;
}

else
{
ans= - comp[4]* pow(2,4);
j=3;
}
if (i >= 0)
{
ans=ans + pow (2,j)*comp[j];
b=b+1;
j=j-1;
}
else
cout<<"Your Number is:"<<ans;
return 0;
}
Topic archived. No new replies allowed.