Hey, I have no idea why this code isnt working, im new to C++ so maybe im missing some fundamentals or something. But to me it looks perfectly fine.. the purpose of this program is to change binary into user code... if someone could help me out it would be very appreciated ^.^
#include <stdlib.h>
#include <stdio.h>
int main ()
{
int nextDigit,oneDigit;
char binaryNumber;
//prompt user for binary #
printf("Please enter a binary number\n");
scanf("%c", &binaryNumber);
/*assign variable decimalValue 0*/
int decimalValue=0;
/*obtain variable nextDigit
(the first digit in the binary number, then the next and so on.)*/
oneDigit=getchar();
if (oneDigit != 1 || oneDigit != 0)
printf("invalid binary digit was entered.\n");
else
{
while (oneDigit == '1' || oneDigit == '0');
{
/*assign variable decimalValue
the value of (decimalValue*2)+nextDigit*/
decimalValue = ((decimalValue*2) + oneDigit);
}
printf("%i",decimalValue);
}
system("PAUSE");
return 0;
}