Hey there,I'm looking for assistance with my simple code here.

Why do my integers ( x,v,z,d,e,f,g,h ) suddenly change when the program reaches the " printf("The decimal value is... " part? Is there something I'm missing?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
int Binary[7],x,v,z,d,e,f,g,h;
Binary[0]=x;
Binary[1]=v;
Binary[2]=z;
Binary[3]=d;
Binary[4]=e;
Binary[5]=f;
Binary[6]=g;
Binary[7]=h;
int decimal,numm0,numm1,numm2,numm3,numm4,numm5,numm6,numm7;

decimal = x*128+v*64+z*32+d*16+e*8+f*4+g*2+h*1;  
 numm0=x*128;
 numm1=v*64;
 numm2=z*32;
 numm3=d*16;
 numm4=e*8;
 numm5=f*4;
 numm6=g*2;
 numm7=h*1;

printf("Binary to Decimal conversion");
printf("\n==========================\n");
printf("Please enter a 8-digit Decimal:");
scanf("%d,%d,%d,%d,%d,%d,%d,%d",&x,&v,&z,&d,&e,&f,&g,&h);
printf("Your entered value is %d\n",x,v,z,d,e,f,g,h);
printf("The decimal value is\n(%dx128=%d)+(%dx64=%d)+(%dx32=%d)+(%dx16=%d)+(%dx8=%d)+(%dx4=%d)+(%dx2=%d)+(%dx1=%d)=%d\n",x,numm0,v,numm1,z,numm2,d,numm3,e,numm4,f,numm5,g,numm6,h,numm7,decimal);




system("pause");
return 0;
}

Hey there,I'm looking for assistance with my simple code here.

If you can't figure it out, it's not that simple, is it? :icon_wink:

Why do my integers ( x,v,z,d,e,f,g,h ) suddenly change when the program reaches the " printf("The decimal value is... " part? Is there something I'm missing?

Define "suddenly change"? What did they start out as and what do you think they became? Since you never output any of those variables until after you scanf() 'd them, how do you know anything happened to them?

Sorry, but based on the code, the question is nonsensical. Think through the question again and restate.

It appears that you are using variables x,v,z,etc before assigning valid values to them.
You should compute num1,num2,etc only after the scanf(...) statement..

This article has been dead for over six months. Start a new discussion instead.