1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Decimal to binary conversion trouble

Discussion in 'C++' started by bmos31, Sep 1, 2010.

  1. bmos31

    bmos31 New Member

    Joined:
    Sep 1, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I'm having trouble even getting started with this problem. I've tried looking at other examples, but I'm completely stuck.

    The question and my code(not even sure if im on the right track) is as follows:

    Write a function called decToBinaryString that recieves a non-negative int and returns a string that is a binary representation of the number input.
    tips - concatenate strings together
    test odd/even using %
    write a main() that test the code

    Code:
    #include<iostream>
    
    using namespace std;
    
    void intToBinaryString(unsigned long int, char *);
    
    #define ARRAY_SIZE 1000
    
    int main()
    {
        unsigned long int number;
        char binary[ARRAY_SIZE];
        int i;
    
        cout << "Enter a non-negative integer to convert to binary: ";
        cin >> number;
        intToBinaryString(number, binary);
        
        cout << "Binary representation: ";
        for(i = 0; i < binary
        system ("pause");
        return 0;
    }
    
    void intToBinaryString(unsigned long int num, char *bin)
    {
        int remainder; 
        <strong class="highlight">if</strong>(num%2 == 0)              //even
        {
            do
            {
                remainder = num%2;  
            }while(num > 0);
            
        
        else                        //(nonNeg%2 != 0) odd
                        
    }
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0

Share This Page