Determine number of even, odd, and zero digits of a given integer I have been programming in C++ for around a month now, just long enough, I figure, to develop bad habits. Can anyone point out where I'm making mistakes and offer topics I should investigate to understand why?

#include &lt;iostream&gt;
#include &lt;cassert&gt;
#include &lt;sstream&gt;
#include &lt;string&gt;

using namespace std;
string get_line();
int long get_integer();
int* flex(long int num);
void test_flex();

int main()
{ 
    //flex(get_integer());
    test_flex();
}

/* 
 * ===  FUNCTION  =============================================================
 *         Name:  flex
 *  Description:  flex takes one integer argument and returns an then number
 *  of odd, even and zero digits.
 *  flex(111022) -&gt; [3,2,1] i.e [odd,even,zero's]
 * ============================================================================
 */
    int*
flex (long int num)
{
    int res;
    int even = 0;
    int odd = 0;
    int zero = 0;

    while(num != 0){
        res = num % 10;
        if(res == 0){
            zero++;
        }
        else if(res % 2 == 0){
            even++;
        }
        else{
            odd++;
        }
        num = (num - (num % 10))/10;
    }
    int oez[3] = {odd,even,zero};
    return oez;
}       /* -----  end of function flex  ----- */

/* 
 * ===  FUNCTION  =============================================================
 *         Name:  test_flex
 *  Description:  test suite for flex function
 * ============================================================================
 */
    void
test_flex ( )
{
    assert(flex(1)[0] == 1); 
    assert(flex(1)[1] == 0);
    assert(flex(1)[2] == 0);

    assert(flex(112220)[0] == 2);
    assert(flex(112220)[1] == 3);
    assert(flex(112220)[2] == 1);

}       /* -----  end of function test_flex  ----- */

/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  get_integer
 *  Description:  checks if input is integer
 * =====================================================================================
 */
    long int
get_integer ()
{
    while(true){
        stringstream converter;
        converter &lt;&lt; get_line();

        int long result;
        if(converter &gt;&gt; result){
            char remaining;
            if(converter &gt;&gt; remaining)
                cout &lt;&lt; "Unexpected character: " &lt;&lt; remaining &lt;&lt; endl;
            else{
                return result;
            }
        } else
            cout &lt;&lt; "Please enter an integer." &lt;&lt; endl;

        cout &lt;&lt; "Retry:" &lt;&lt; endl;
    }
}       /* -----  end of function get_integer  ----- */


/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  get_line
 *  Description:  wraps getline
 * =====================================================================================
 */
    string
get_line()
{
    string result;
    getline(cin,result);
    return result;
}       /* -----  end of function get_line  ----- */
Do not see the point in: get_line()

get_line(line);

// Vs

std::getline(std::cin, line);


Get Integer is well done. Most people forget to test if there is anything else remaining on the line.

A simple enhancement is:

        char remaining;
        if(converter &gt;&gt; remaining)

        // easier to rewrite as:
        if (!converter.str().empty())


Also there is already a boost function that does something similar:

long value = boost::lexical_cast&lt;long&gt;(line); // Will throw if anything left on line.


Over complicating this:

    num = (num - (num % 10))/10;


You can simplify it too:

    num /= 10;  // Integer division truncates.


I think this is a logical error:

    if(res == 0){
        zero++;
    }
    else if(res % 2 == 0){ // zero is an even number
                           // do you really want that else?


Your one major error is:

int oez[3] = {odd,even,zero};
return oez;


You are returning a pointer to an array that has gone out of scope. Personally I would return a std::vector&lt;int&gt;. Don't worry on a simple returning like this the copy back of the array will be optimized out (look up RVO and NVRO).

std::vector&lt;int&gt; oez = {odd,even,zero};
return oez;