exiting a program

Suppose I wanted a particular key, lets say 4 to exit the program. How would I go about that? More along the lines of cases. By that I mean this is an if case where it just exits the program.

if(x==1)
.....something happens....
if(x==2)
.....something happens....
if(x==3)
.....something happens....
if(x==4)
// The program exits out
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
     if(x==1)
          // .....something happens....
     if(x==2)
          //.....something happens....
     if(x==3)
          //.....something happens....
     if(x==4)
         return 0;

     ...
     return 0;
}
Last edited on
Not that. I meant that the program actually exits out. As soon as they hit 4, the whole screen will be exited out completely.
Clearing the Screen? http://cplusplus.com/articles/4z18T05o/

EDIT: And you better use switch/case.
Last edited on
I suppose you're referring to a menu of some sort. Da0omph's example of return 0; will exit the application. When main() runs into the first return statement, it exits, but if x doesn't equal 4, it will finish running the program until it hits the last return 0; statement.
Topic archived. No new replies allowed.