By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,122 Members | 1,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,122 IT Pros & Developers. It's quick & easy.

How to completely end a program if some condition given holds true?

P: n/a
For example if some variable lets say..a is greater than 10 then
program should close....

i.e
"press any key to continue" message appears.

Dec 30 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 2006-12-30 18:48, fa***********@hotmail.com wrote:
For example if some variable lets say..a is greater than 10 then
program should close....

i.e
"press any key to continue" message appears.
#include <cstdlib>
if (a 10)
exit(0);

--
Erik Wikström
Dec 30 '06 #2

P: n/a

Erik Wikström wrote:
On 2006-12-30 18:48, fa***********@hotmail.com wrote:
For example if some variable lets say..a is greater than 10 then
program should close....

i.e
"press any key to continue" message appears.

#include <cstdlib>
if (a 10)
exit(0);

--
Erik Wikström
Good hit!
thanx for helping a youngster,

Dec 30 '06 #3

P: n/a
On 2006-12-30 19:11, fa***********@hotmail.com wrote:
Erik Wikström wrote:
>On 2006-12-30 18:48, fa***********@hotmail.com wrote:
For example if some variable lets say..a is greater than 10 then
program should close....

i.e
"press any key to continue" message appears.

#include <cstdlib>
if (a 10)
exit(0);

--
Erik Wikström

Good hit!
thanx for helping a youngster,
I'd like to point out that it might be better to cast an exception which
is at last caught in main() from where you return instead of using exit,
since this gives you the chance to catch the exception as it propagates
through the call-stack and do some cleaning up (closing files/sockets or
whatever) before re-throwing it.

--
Erik Wikström
Dec 31 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.