Monday, December 12, 2011

Binary to Decimal, C programming. Help my code!?

Hey guys, I've tried this and when I run it it's outputting 0, and I'm puzzled. Figured a new set of eyes might help me.





int BtoD( int binary ) // converts binary to decimal


{


int count;


int total;


char Bin[8];





itoa(binary, Bin, 10);


for (count = 0; count %26lt; strlen(Bin); count++)


{


if (Bin[count] == 1)


{


total = 2^count;


}


}





return 0;


}





//Here is the call elsewhere


decimal = BtoD(binary);


printf("\tBinary: %d = Decimal %d\n\n", binary, decimal);





//Some variables in main


int selection;


int binary;


int decimal;





Thanks guys!|||it's because your returning 0





return 0; returns nothing


You want to return your total so replace return 0; with return total;

No comments:

Post a Comment