When you execute a method there are to ways to leave:
1) You can explicitly use a
return
statement:
if (again != 'y')
{
PlayAgain = false;
return 0;
}
When
return
is executed, the method exits at that point and no further code is executed.
2) If your code reaches the closing curly bracket for the method, it exits the method as it has no further statements to run:
int main()
{
...
}
This can prevent your code for even compiling as it doesn't specify a return value, so unless your method is declared as returning a
void
value, many compilers will issue an error on this.
And when your code exits the
main
method, your application ends as well.
So in your case, you need to provide some way to "go around again" in your method, or it will always close the app when the user has made a selection.
In this case, I'd suggest that you use a
C++ do while
Loop[
^] and use the existing
if
condition to exit that instead of
return
.