
July 6th, 2003, 12:02 AM
|
|
Junior Member
|
|
Join Date: Jul 2003
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Binary to Decimal Code, needing help.
After a rather long break from programming in C I recently started again. After brusing up on it I decided to write this code off the top of my head.
I'm not quite sure exactly what's wrong with it, I've spent a few hours just staring at it. Theoretically, when run it prompts you to enter the binary to be converted. (currently only 4 digits for simplicity's sake.) and then return a value after the calculations have been made. In reality, At a DOS prompt it asks for the Binary and after that has been entered it encounters a fatal error.
I've broken up the code into sevral functions after writing it in one big Chunk. If you can debug this simple program, please please e-mail me with the code and a short explanation of what was wrong. My E-mail is thewiccakid@hotmail.com , thank you.
-JG
PHP Code:
#include <stdio.h>
#include <string.h>
int buns[4];
int weiner[4];
int a = 0;
int y, z;
void calculate_1(){
for (y = 0; y < 4; y++){
weiner[y] = buns[y]*2^(3 - y);
}}
int calculate_2(){
for (y = 0; y < 4; y++) {
weiner[y] = z;
a += z;
}
return 0;
}
int results(){
printf("The decimal equivalent of %d is:\n", buns);
printf("%d", a);
return 0;
}
main ()
{
printf("Please input the Binary to be converted to decimal:\n");
scanf("%d %d %d %d", buns[0], buns[1], buns[2], buns[3] );
calculate_1();
calculate_2();
results();
}
|