Hi, im new to c++, and right now im trying to get a program to loop....actually its more of a count down...Im trying to make it so the Program says "Please enter starting number>_" and when you enter the number, it will show a count down and then eventually display a message...Here is the code i am using-
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;
}
Now, when i enter the number, the dos window just closes...
I think i need to insert a pause command somewhere...but im not sure where...if not pause, what is it? help would be greatly appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can also run command.com and switch to that directory. That is an alright method if you want to see your programs output without using a pause command.
Oh and welcome to C!
Now stop using those nasty Cout commands, they make me eyes hurt! ;)
Gair
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
One small point as well - it is not a "dos window", it hasn't been a "DOS" window
for quite a few years now.
As Clifford pointed out, when the program ends, the window closes - SO - solutions
to keep the window open involve keeping the program from finishing. You can even
do it as simply, and crudey like this
int waynesadummy;
cin >> waynesadummy;
I mention this to avoid the "magic word" way of thinking. The key to getting things
to work is not knowing the magic word, its understanding what is happening and why.
If you understand the what and why, the how is a lot easier to work with.
So, as you are learning things, please, try to avoid the trap of "OK, there is
a magic word to do that, that's all I need to know, I don't need to know why
it works"
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, im new to c++, and right now im trying to get a program to loop....actually its more of a count down...Im trying to make it so the Program says "Please enter starting number>_" and when you enter the number, it will show a count down and then eventually display a message...Here is the code i am using-
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;
}
Now, when i enter the number, the dos window just closes...
I think i need to insert a pause command somewhere...but im not sure where...if not pause, what is it? help would be greatly appreciated.
You can also run command.com and switch to that directory. That is an alright method if you want to see your programs output without using a pause command.
Oh and welcome to C!
Now stop using those nasty Cout commands, they make me eyes hurt! ;)
Gair
Replace your line "return 0" with:
Hey, thanks alot!
When a program completes its windows closes - normal behaviour; how have you never noticed that before!?
One small point as well - it is not a "dos window", it hasn't been a "DOS" window
for quite a few years now.
As Clifford pointed out, when the program ends, the window closes - SO - solutions
to keep the window open involve keeping the program from finishing. You can even
do it as simply, and crudey like this
int waynesadummy;
cin >> waynesadummy;
I mention this to avoid the "magic word" way of thinking. The key to getting things
to work is not knowing the magic word, its understanding what is happening and why.
If you understand the what and why, the how is a lot easier to work with.
So, as you are learning things, please, try to avoid the trap of "OK, there is
a magic word to do that, that's all I need to know, I don't need to know why
it works"
Wayne
How had i never noticed it before? I told you...im very new to c++...cut me some slack.