the while loop

i"m new and just started learning c++ and im on while loops but it doesnt stay up on my screen it just closes as soon as it opens
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include "stdafx.h"
#include <iostream>
using namespace std;

int main ()
{ 
int n;
cout << "Enter the starting number > ";
cin >> n;

while (n>0)  {
cout << n <<",";
--n;
}
cout<<"FIRE!\n";
return 0;
}
Last edited on
It's more than likely because you've got the statement "FIRE". lol jk

If you're using a Windows operating system (OS), then before the "return 0;" line, put "system("pause");" that way it doesn't close right away, and will require you to push a key to close the window.

If it still doesn't work, have the directive "#include <stdlib.h>".

Don't include the quotation marks :)
Please see the sticky thread (top of this page) for better alternatives:
http://www.cplusplus.com/forum/beginner/1988/
Have a look at the "Console closing down " topic which is stickied in the beginners section. It is stickied for a reason .....
you should add the system pause like this
1
2
3
4
return 0;

    system ("pause");
}
thanks andrey it worked
Topic archived. No new replies allowed.