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: 
For your described problem: [Preventing console window from closing on Visual Studio C/C++ Console application](https://stackoverflow.com/questions/1775865/preventing-console-window-from-closing-on-visual-studio-c-c-console-applicatio)

For your code, there seems to be a mistake, and currently your code will not produce a pyramid, but a slash of `O`. To solve this problem:

`for (k = 1; k <= 2 * i - 1; k = k + 1);` remove the `;` from this line. **Why this solved the problem?**

When there is a `;` after the loop, it means that the loop does nothing, and then the next three lines are:

```
{
    printf("O");
}

```

Which means that there are only a single `O` prints out, instead of printing it in a loop.
You should include conio.h header file in your program and then simply place getch(); after your program's last cout statement.

I think that this would help the window from closing
it worked for me ;)