You
can end the program with
exit(0);
but 99.9999999% of the time it's the wrong thing to do.
The larger problem here is that your overall structure is all wrong. You're using functions incorrectly -- as if they were gotos.
Functions have 2 major purposes:
1) They break code up into smaller tasks so that it's easier to manage
2) They allow for code reuse since you can call the same function from different parts of the program.
Since this program is pretty small, you're only really concerned with point #1: splitting the overall job into smaller tasks.
The problem is "correctPassword" isn't a task. It's more like a label name (again, you seem to be thinking of it as if it's a goto)
Examples:
void GetUserInput();
is a good function
void UserPressedA();
is a bad function
bool IsGreaterThan3(int v);
is a good function
bool Section3(int v);
is a bad function
To help change your mindset, names of functions should be verbs. That is, what the function does and/or returns can be summed up in the function name.
zachwulf's point of functions overcomplicating things in this case is probably true.
Also...
how to I return to the beginning of the function once the correct password has been entered? |
If you want code to repeat (aka "loop"), put that code in a loop.