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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.