Question: So I wanted to write a program which prints out a pyramid made out of "O", whose height is given by user input.

```
#include <stdio.h>

int main()
{

    int n, i, j, k;
    scanf_s("%d", &n);
    {
        for (i = 1; i <= n; i++)
        {
            for (j = 1; j <= n - i; j++)
            {
                printf(" ");
            }
            for (k = 1; k <= 2 * i - 1; k = k + 1);
            {
                printf("O");
            }
            printf("\n");
        }
        return 0;
    }
}

```

I'm a complete beginner, so if you have any advice, please do offer it. Anyways, I tried running it on a compiler on Android; seemed to work, printed out the pyramid.

Tried it on Microsoft Visual Studio. The command line opens, but after I put in the number and press "enter", the whole window just closes without giving me anything. How do I prevent this? Programs that don't need user input seem to run just fine.

Answer: 
Once console application returns from main method, the associated console window closes automatically. For Windows OS add a `system("pause");` before your `return 0;` statement. For platform independent solution you can just show a prompt to user and wait for a key press before returning from main. Any character remaining in input buffer (enter from scanf in this case) must be cleared.

```
int main()

{
   .........
   .........
   //clear input buffer
   int d;
   while ((d = getchar()) != '\n' && d != EOF) { }
   printf("Press ENTER key to Continue\n");  
   getchar(); 
   return 0;
}

```
Put a cin command(C++) or a C equivalent at the very end just before return 0;, so it wont close. :>
Eg:

```
.
.
.
.
int control; cin>>control;
return 0;
}

```