I need help with a program I am writing

ObiWan506

Solid State Member
Messages
20
Hey guys, I am in the middle of writing a program (in "C") to help me convert Decimal numbers to Binary numbers but I need some help. I wrote the program but I know it isn't right, so I was wondering if I can post it here and maybe you guys can help me out. Here it is:

Code:
[B]#include <stdio.h>

int main()
{
    int a, b, c;
     printf("Enter the variable:");
     scanf("%d", &a);
     b = a / 2;
          if b < 2
          {
          c = b /2;
          }
     printf("%d", "%d", b, c);
}[/B]
Thank you for you help, :)
 
Well specifically, my compiler is saying the following things:

1 - Line 9 - Syntax error found 'b' expecting '('
2 - Line 10 - Missing closing parentheses before '{'
3 - Line 13 - printf: too many argument
4 - Line 14 - Missing return value

And unspecifically, the way I see it, my question is how to I tell the program to tell the difference between a "1" & a "0"? And also what if I have a 4 digit answer instead of a 3 digit answer, do I claim more variables? But if I claim more variables and my answer is a 3 digit answer, what happens to the extra variable? Thanks for the help.


P.S. - By the way, please don't tell me to fix the problem by using the Force, I get enough of that joke with the name that I have. j/k :)
 
Indeed! but the Force knows nothing about Computers! Computers aren't about what your brain can do, or indeed what your body can do - Computers are about complete and utter balls ups! After a few Balls ups you get fast at doing them and learn from them; so after a couple of minutres you've made so many balls ups that you know what to do and are good at that afterwards.

Now, I don't claim to know anything about C Language (although it shouldn't be too soon know - I went to work today and now I am 3/4 the way to buying Visual!); and its far to late or me to even think of this problem in a Logical Way as a Maths Question! But I can find a changer!

Here is the problem in Java:

Kalthorn's searched for Java said:
}
function Decimal_to_binary(x)
{
answer=new Object();
x2=x;
log2=0;
while(x2>=2){
x2=x2/2;
log2=log2+1;
}
for(l2=log2; l2>=0; l2--){
power=Math.pow(2,l2);
if (x>=power) {
answer[l2]="1";
x=x-power;
}
else answer[l2]="0";
}
for (i=log2; i>=0; i--){
document.forms[0].elements[1].value+=(answer);


I would try and help you translating that - and if you haven't posted byt tommorow evening I'll go though it any way! I hope that can help you for now anyway.

Why are you doing it?
 
Well to answer your last question, I am doing this to teach myself. I found computers to be an interesting field for me, more specifically programming was always something I wanted to learn. I plan on taking classes in August, but until then I want to learn as much as I can so I am teaching myself. This program (Decimal to Binary) is just another step I made to help me learn more through experience. Anyway, I appreciate your posts and am looking forward to you explaining/transalate the code you provided in your post Lord Kalthorn. Thank You.
 
ObiWan506 said:
Well to answer your last question, I am doing this to teach myself. I found computers to be an interesting field for me, more specifically programming was always something I wanted to learn. I plan on taking classes in August, but until then I want to learn as much as I can so I am teaching myself. This program (Decimal to Binary) is just another step I made to help me learn more through experience. Anyway, I appreciate your posts and am looking forward to you explaining/transalate the code you provided in your post Lord Kalthorn. Thank You.

Lol! So am I!

I will not be able to put it on now; but I'm still working on it and I shall come back after dinner and tell you what I have found. It will be in an equation but with that the fun of translating it into C Language I will leave to you.

Cool, I also wish to learn C Language - but I most certainly won't be taking classes - as there is nowhere anywhere near me which could even do it! I plan to learn through the balls up trial and error method after I get Visual Studio!
 
Lord Kalthorn said:
Lol! So am I!

I will not be able to put it on now; but I'm still working on it and I shall come back after dinner and tell you what I have found. It will be in an equation but with that the fun of translating it into C Language I will leave to you.

Cool, I also wish to learn C Language - but I most certainly won't be taking classes - as there is nowhere anywhere near me which could even do it! I plan to learn through the balls up trial and error method after I get Visual Studio!
They do an evening corse at the lansdown college.
 
Lord Kalthorn, teaching yourself is definetly hard (as I have found out myself) but it definetly is the most rewarding! I look forward to your post later on, thanks again for helping me out with this program!
 
Back
Top Bottom