Format an integer with thousands separator (recursive implementation) The function accepts a number n and displays it recursively with commas.

As well as a general code review, I'm interested in suggestions for alternatives to counting to tell when to print the commas.  I tried if(mod%10000 == 0); that works on the first 3 numbers, but after that mod is always a multiple of 10000.

#include &lt;iostream&gt;
using namespace std;

void RecursiveCommas(long long n, int mod = 10, int i = 0);

int main()
{
    RecursiveCommas(123456789);
    return 0;
}

void RecursiveCommas(long long n, int mod, int i){
    if(n%mod==n){ //base case
        if(i%3 == 0 &amp;&amp; i != 0)
            cout &lt;&lt; (n%mod) / (mod/10) &lt;&lt; ",";
        else
            cout &lt;&lt; (n%mod) / (mod/10);
    }
    else{
        if(i%3 == 0 &amp;&amp; i != 0){ //add commas
            RecursiveCommas(n, mod*10, i+1);
            cout &lt;&lt; (n%mod) / (mod/10) &lt;&lt; ",";
        }
        else { //no comma needed
            RecursiveCommas(n, mod*10, i+1);
            cout &lt;&lt; (n%mod) / (mod/10);
        }
    }
}
ArtemyVysotsky has provided you with a improved solution, so I am just going to give some general advice:


Do not use using namespace std; since it not only lowers readability of your code (things that belong to the standard library are no longer easily discernible) but also opens the door for subtle name resolution bugs.
n is of type long long, but mod is only of type int. Since mod grows until n % mod == n, you are running into the risk of overflow here, so mod should also be of type long long. However, since mod should never be negative, it would be even better to have it be a unsigned long long/
Keep your spacing consistent. For example, why do you sometimes leave space around == and other times don't? There is no right coding style that everyone agrees on, so you are free do choose any option that fits you, but you should at the very least stick to the style you choose throughout your code (also, keep in mind that most programmers consider more space better than less space, so leaving a space around operators is generally better received than not doing so).
Consider wrapping your recursive function in a helper function. Anyone who doesn't know about your code would assume that all three parameters your function takes can and should be passed by the caller when the last two arguments aren't actually supposed to take anything but their default value. 
Don't treat single characters as strings when treating them as chars would work fine. In particular, prefer std::cout &lt;&lt; ... &lt;&lt; ','; over std::cout &lt;&lt; ... &lt;&lt; "," since this is (likely to be) faster and more efficient.
Having a function output do std::cout directly severely harms its uses. For example, what if I want to send the formatted number to a file? Currently, your function doesn't help much with that. There are several possible improvements here, for example building and returning a std::string or taking an std::ostream as a parameter and output to that instead.
You don't actually need return 0; in main, the compiler is nice enough to add that automatically (Beware, however, as this only happens in main!).