I am testing to see if a correct password is entered in 3 attempts, if it is not, the program exits, if its correct, it return back to the main. I made a try but not sure how to finish it off. Cant get it to display the "test" message.
Yeah but if I remove exit(1); , no matter the inputs, it always goes straight back to the main function instead of exiting there if 3 incorrect passwords are entered.
One can use return in function that returns no value:
1 2 3 4 5 6 7 8
void foo( int a ) {
// code
if ( .... )
{
return;
}
// code
}
There is an implicit return; at the end of such function.
From that follows that the exit(1) at line 28 is the problem. However, I would change the void Login() into bool Login() and returnfalse; on line 15 and line 28.
However, you do have a problem in Login(). Your while-loop terminates on two situations:
1. Correct password
2. Too many attempts
But what do you do on lines 27-28? You terminate the program anyway. You should check on line 26 for the true reason and perhaps returntrue; on "success".
Likewise, return 1; would be fine on line 43, and then return 0; at the end of main().
If you return bool from Login(), then in main() line 51 you can test whether the function was a success: