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: 
Apart from the semicolon after the `for (k = 1...` loop, you have no bug in this code; if Visual Studio closes, the issue is with that program. (It could well just be closing because the program has finished execution, but I don't know that program).

Since you write that you are a complete beginner and you would appreciate advice, I'll offer some stylistic comments. But these are just comments on how I would do things differently if I were you, I am not saying that what you have is wrong.

* Single-letter variable names: these will bite you. It is really easy to mix up i, j, and k since they are all kind of meaningless indexes. When your programs become more complex you will be happy to have meaningful variable names. Also, if you are trying to locate instances of a variable, searching for 'i' is a lot harder than searching for "spaces" or "spc"
* Code block under scanf\_s(): There is no reason to have this code inside a block--all that does is shift the internal code one tab right. Screenspace is precious.
* You will likely find it more useful to iterate from 0 than from 1, as you will be using your iterator variable as an array index a whole lot. Getting into the habit of writing your loops as `for (dex = 0 ; dex < max_val ; dex++)` will serve you well. Note well that the comparison is "dex < max\_val" and not "dex <= max\_val"
* The "k = k + 1" seems bad to me--people reading your code will need to stop and try to figure out why it's not just "k++" which what people are expecting and what you use in the other two loops. (And even for incrementing-by-more-than-one I'd expect something like "k += 2" not "k = k + 2")
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 ;)