Thread: Debugging question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    4

    Debugging question

    Hi guys, im kinda new here, so if i make a newbi mistake please go easy on me.

    Well Im trying to make a program that will convert binary to decimal. (I know there are thousands of these post already, but i still couldnt find the answers to my question .


    question # 1:
    How can i pervent people from entering numbers other than 1's and 0's ?

    question #2:
    For some reason when I enter the binary, Im only able to enter 5 digits or less, or else my program wront work.
    For e.g. i enter 11011 :: the output will be 27
    But when i enter 111101 :: the output will be 0


    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int array[1000];
    int getbinary(int binary);
    
    main()
    {
    	int temp;
    	int binary;
    	int power;
    	int decimal;
    	int cell;
    	cell = 0;
    	power = 1;
    	decimal = 0;
    	binary = getbinary(binary);
    
    	do{
    		temp = binary % 2;
    		if (temp==1)
    		{
    			array[cell] = power;
    		}
    		else
    		{
    			array[cell] = 0;
    		}
    		cell++;
    		power = power * 2;
    		binary = binary * .1;
    	} while(binary > 0);
    	for (cell=cell; cell>=0; cell--)
    	{
    		decimal = array[cell] + decimal;
    	}
    	printf("%d decimal\n", decimal);
    	getch();
    }
    
    int getbinary(int binary)
    {
    	printf("Please enter binary: ");
    	scanf("%d", &binary);
    	return binary;
    }
    Thx!!
    Last edited by o_0; 10-10-2004 at 12:15 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dev-C++: Problems with Breakpoint Debugging
    By Thileepan_Bala in forum C Programming
    Replies: 1
    Last Post: 01-17-2008, 10:48 AM
  2. Debugging book recommendation
    By dagans in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 09-13-2005, 07:35 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. Debugging Question
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 12-19-2001, 05:42 PM