anonymous
2011-06-29 20:25:33 UTC
I know that I'm close. it prints the wrong number and I can't figure out why. Please, provide explanation to corrections. Thanks. (Also, please try to work with THIS program, rather than giving me something totally different.). this is an intro to programming course. I think my problem is in getting it to read the 8 digits individually from right to left.
#include
#include "conio.h"
int main()
{
double bin[8], decimal=0;
float exp=0.5;
int i=0;//define variables
printf( "type the binary number:\n");//prompt the user for binary number
scanf ("%lf", &bin[i]);
for (i=7; i>=0; i--)
{
exp*=2;//function represents powers of 2
decimal+= (bin[i] * exp);
}
printf("The decimal is %lf", decimal);//prints decimal
_getch();
return 0;
} //end this program