Code:
#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[]) {
unsigned char c, b, n;
int sum, done;
sum=0;
done=0;
int i=8;
n=0;
printf("Enter a binary number:");
c=getchar();
if (c=='q'||c=='Q') {
getchar();
return 0;
} else {
for ( int x = 0; x < 8; x++ ) {
b=c&1;
n=n<<1;
n=b|1;
}
sum=sum+n;
printf("sum = %d decimal %x hex and " , sum, sum);
}
getchar();
return 0;
}
Formated your code so I could read it, then, changed the for(;; to getchar();. Your intent with the for(;;s was to pause the program right? Well pausing for user input is a lot healthier of a way of doing that, and since you are allowed to use getchar(), why not !
As to your input issues, you are only reading one character, and assuming you follow what your program told you to do, you will get either a '0' or a '1' (which, btw are the ascii symbols 0 and 1, the value stored in the char isn't actually the number 0 or 1) If you want to read more characters, you are going to have to loop, that is, if you have to use getchar().