470,831 Members | 1,997 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,831 developers. It's quick & easy.

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 2753
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

Post your reply

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

Similar topics

2 posts views Thread by Sverre Bakke | last post: by
2 posts views Thread by Mariusz Sakowski | last post: by
15 posts views Thread by jaks.maths | last post: by
5 posts views Thread by Jeff Dillon | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.