0

Hello,

I know that "break" is used to end a loop, but how does one exit a C++ console program, after the user enters a negative value, without using a loop?

For example, I would like to do this:

if (value == -1)
{ system("exit");}

But the code above does not work. I included stdlib.h, without any success

2
Contributors
1
Reply
6
Views
10 Years
Discussion Span
Last Post by Salem
0

Use the function called exit();

As in

exit(0);
exit(EXIT_SUCCESS);
exit(EXIT_FAILURE);

Or if you're in main(), you can use these values with the return statement.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.