473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

converting decimal to binary

3
Hi there
]i am new to C programming and totally lost.
iam trying to convert decimal to binary. here is what i did
please ignore the case h and m. I am trying to get case 'b' to work.
i do not want to use cout and cin. is there any other way to change the last function. please someone help me.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. int main( )
  5. {
  6.   char cmd = '.', tmp, tmp2;
  7.   int counter = 0;
  8.   int number = 0;
  9.  
  10.   printf( "Converter Program v1.0\n" );
  11.  
  12.   do
  13.   {
  14.      printf( "(q for quit, h for help)\n> " );
  15.      scanf( "%c%c", &cmd, &tmp );
  16. //     printMenu( );                            //prototype for printMenu()
  17.   //   Monthname( number );
  18.      void binary ( number );
  19.  
  20.    switch( cmd )
  21.      {
  22.     /*    case 'h':
  23.                 printMenu( );                 // calling the function printMenu
  24.                 break;
  25.         case 'm':
  26.                 printf( "What month? Enter a number between 1 and 12: " );
  27.                 scanf( "%d%c", &number, &tmp );
  28.                 Monthname( number );
  29.                 break;*/
  30.         case 'b':
  31.                printf( "What decimal number would you like converted to binary? " );
  32.                 scanf( "%d%c", &number, &tmp2 );
  33.                 printf( "%d in binary is: ", number );
  34.                 void binary( int number );
  35.  
  36.                 break;
  37.      }
  38.   } while( cmd != 'q' );
  39.   printf( "Good Bye!\n" );
  40.   return 0;
  41. }
  42.  
  43. void binary( int number )
  44. {
  45.     int remainder;
  46.  
  47.     if(number <= 1)
  48.     {
  49.         number;          // i know this is wrong. is there any other way besides cout
  50.  
  51.     }
  52.  
  53.     remainder = number%2;
  54.     binary(number >> 1);
  55.      remainder;
  56. }
Oct 17 '07 #1
1 2921
rhitam30111985
112 100+
rhitam-

I know we've asked you not to spoonfeed already. Please provide details on how the OP can change their code.
Oct 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sverre Bakke | last post by:
Hi I am using the base_convert() function to convert numbers between binary, hexadecimal, decimal, etc... It works great, but I have problems converting numbers with .'s Like this number: ...
2
by: Mariusz Sakowski | last post by:
I'm writing class which will be able to store large numbers (my ambition is to make it able to operand on thousands of bits) and perform various operations on it (similiar to those available with...
25
by: TK | last post by:
I'm used to programming in c or c++ in which my problem is simple. I want to be able to enter a value on a page (like 3.2), and then read it as a 32-bit float and break it into it's individual...
2
by: geskerrett | last post by:
In the '80's, Microsoft had a proprietary binary structure to handle floating point numbers, In a previous thread, Bengt Richter posted some example code in how to convert these to python floats;...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
5
by: Jeff Dillon | last post by:
How might I convert a string like 10.A (in hex) to it's decimal equivalent? Basically I have an input string like ((1F.A + 3A.D) - 1F.E) and need to calculate the result. Using Reflection and...
2
by: Tukeind | last post by:
Hello, I am receiving the following error: error C2065: 'to_binary' : undeclared identifier while running the code below. If anyone can help I'll appreciate it? Thank you, Tukeind
0
by: Terry Reedy | last post by:
A. Joseph wrote: These are number representation systems that can be applied to or used with integral, rational (numberator,denominator), and 'point' numbers. Try Wikipedia or any search...
0
Frinavale
by: Frinavale | last post by:
Convert a Hex number into a decimal number and a decimal number to Hex number This is a very simple script that converts decimal numbers into hex values and hex values into decimal numbers. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.