times(x, y, z, isvalid);
You pass a copy of isvalid to the function which always will be true; you need to pass it as a pointer or reference if you want the function to change the value.
if (isvalid = true) You just assign true to the variable, comparision operator is ==
BTW. If you compile your code with all warnings on, the compiler should warn you.
When I run your program it exits properly when I entered -1.
By properly I mean that it displayed the message "The answer is correct. Good Job!" then exited the program.
By the way your program will always display the above message, since you used the assignment operator instead of the comparison operator in the if() statement.
It now won't exit because z can never be -1 at the end of the while statement, it will always be the "correct" answer since that is the only way you can get past the inner loop.
Perhaps you should consider changing the inner while() statement to something like: