Start New Discussion within our Software Development Community

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

#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; 
    if(num%2 == 0)              //even
    {
        do
        {
            remainder = num%2;  
        }while(num > 0);
        
    
    else                        //(nonNeg%2 != 0) odd
                    
}

oh, i just modified my decToBinaryString a little more, but I still need some help

void intToBinaryString(unsigned long int num, char *bin)
{
    int remainder, i; 
    if(num%2 == 0)              //even
    {
        do
        {
            remainder = num%2;
            num = num/2;
            bin[i++] = remainder;  
        }while(num > 0);    
    }
    else                        //(nonNeg%2 != 0) odd
    cout << "this will be for odd numbers";               
}
This question has already been answered. Start a new discussion instead.