Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 02-17-2004, 05:01 PM   #1
Solid State Member
 
ObiWan506's Avatar
 
Join Date: Feb 2004
Posts: 20
Talking I need help with a program I am writing

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:
#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);
}
Thank you for you help,
__________________

ObiWan506 is offline   Reply With Quote
Old 02-17-2004, 05:29 PM   #2
Site Team
 
David Lindon's Avatar
 
Join Date: Dec 2002
Posts: 15,233
Default Re: I need help with a program I am writing

What error are you getting?
__________________

__________________
[url=http://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote
Old 02-17-2004, 07:27 PM   #3
Solid State Member
 
ObiWan506's Avatar
 
Join Date: Feb 2004
Posts: 20
Post

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
ObiWan506 is offline   Reply With Quote
Old 02-18-2004, 03:57 AM   #4
Site Team
 
David Lindon's Avatar
 
Join Date: Dec 2002
Posts: 15,233
Default Re: I need help with a program I am writing

Use the force!
My C knowledge is being streched here. I can't see anything wrong with it.
__________________
[url=http://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote
Old 02-18-2004, 09:34 PM   #5
Guru
 
Lord Kalthorn's Avatar
 
Join Date: Dec 2003
Location: Britain
Posts: 13,293
Send a message via MSN to Lord Kalthorn
Default

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:

Quote:
Originally Posted by Kalthorn's searched for Java
}
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]);
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?
__________________
A Knight is sworn to Honour. His heart knows only Virtue. His blade defends the helpless. His might upholds the Weak. His word speaks only truth. His wrath undoes the Wicked.
Lord Kalthorn is offline   Reply With Quote
Old 02-18-2004, 10:31 PM   #6
Solid State Member
 
ObiWan506's Avatar
 
Join Date: Feb 2004
Posts: 20
Default

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 is offline   Reply With Quote
Old 02-19-2004, 12:58 PM   #7
Guru
 
Lord Kalthorn's Avatar
 
Join Date: Dec 2003
Location: Britain
Posts: 13,293
Send a message via MSN to Lord Kalthorn
Default Re: I need help with a program I am writing

Quote:
Originally Posted by ObiWan506
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!
__________________
A Knight is sworn to Honour. His heart knows only Virtue. His blade defends the helpless. His might upholds the Weak. His word speaks only truth. His wrath undoes the Wicked.
Lord Kalthorn is offline   Reply With Quote
Old 02-19-2004, 01:05 PM   #8
Site Team
 
David Lindon's Avatar
 
Join Date: Dec 2002
Posts: 15,233
Default Re: I need help with a program I am writing

Quote:
Originally Posted by Lord Kalthorn
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.
__________________
[url=http://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote
Old 02-19-2004, 02:41 PM   #9
Solid State Member
 
ObiWan506's Avatar
 
Join Date: Feb 2004
Posts: 20
Arrow

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!
ObiWan506 is offline   Reply With Quote
Old 02-19-2004, 02:44 PM   #10
Site Team
 
David Lindon's Avatar
 
Join Date: Dec 2002
Posts: 15,233
Default Re: I need help with a program I am writing

Just pick up a couple of books on the language.
__________________

__________________
[url=http://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 08:57 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0