ok people i wrote this code myself. i just need your help so this program can accept any digits and print the decimal equivalent. i worte more than i needed too because i wasnt so sure how muchi needed. i dont think it works very well. i tried 1101 and i shud have gotten 13, but i got 8. please help me.

# include<math.h>
# include <stdio.h>
int main()
{
int num;
int fig1,fig2,fig3,fig4,fig5,fig6,fig7,decimal_value,value_1 ,value_2,value_3,value_4,value_5,value_6,value_7;

printf("Enter a binary number:");
scanf("%d",&num);

fig1 =  num /1000000;
num %= 1000000;
fig2 = num/100000;
num %= 100000;
fig3 = num / 10000; 
num %= 10000; 
fig4 = num / 1000; 
num %= 1000; 
fig5 = num / 100; 
num %= 100; 
fig6 = num / 10;
num %= 10;
fig7 = num;

value_1=fig1*64;
value_2=fig2*32;
value_3=fig3*16;
value_4=fig4*8;
value_5=fig5*4;
value_6=fig6*2;
value_7=fig7*1;


decimal_value= value_1 + value_2 + value_3 + value_4,value_5,value_6,value_7;

printf("the decimal value of the binary number entered is: %d",decimal_value);

}

I replaced the commas in line 34 with plus signs and it seemed to work:

decimal_value= value_1 + value_2 + value_3 + value_4,value_5,value_6,value_7;
This question has already been answered. Start a new discussion instead.