The program is just finishing normally - put a call to cin.getline or some other input call if you want it to wait. Alternatively run it through the debugger and put a breakpoint on the return 0 line.
You don't initialize or reset printedStars before you use it. Put printedStars = 0;
before your star printing loops.
Move the setw(5)
bit in the cout calls to before the value, so the value is output with a width of 5.