How to close a program?

Hi!

How can I close a program such that when I press 1 it would close?

I will use switch(x) right?
What will I put under it?

Thanks!
http://www.cplusplus.com/reference/clibrary/cstdlib/exit/

If you're in main(), you can simply return.
How about if I am using stdio.h?
stdio is a library for input and output. It has nothing to do with closing programs. exit is in stdlib header. There is no reason not to include it. You are not restricted to one header. Just look at the example on that page. It uses both stdio and stdlib.

Alternatively, returning in main() exits the program without using any libraries. Though in reality it does exactly what exit().
Ok thanks!
Topic archived. No new replies allowed.