0

(SOLVED) Why will my subMenu() not return a value to menu() that keeps the do while loop going?

This is blowing my mind, because I'm comparing it line by line to other code that works perfectly normally. I just don't understand why the program terminates when I try to return to the main menu. https://code.sololearn.com/chKJJGWgJx4D/?ref=app

15th May 2017, 6:10 PM
Jacob
2 Answers
+ 3
In the subMenu() function, notice that bool menuReturn; is NOT the same bool from your menu() function. So returning to the mainMenu will always fail, as the bool in the menu() is never changed. Here's 2 ways to resolve this. 1) in menu() function: if (user == 1) menuReturn = subMenu(); else if (user == 2) menuReturn = subMenu_2(); else if (user == 3) menuReturn = subMenu_3(); else { // etc... This looks like what you were going for to begin with, as you're returning the value of menuReturn anyway. Or 2) you can pass the reference of the bool menuReturn from the menu() function into the subMenu() function, to actually modify that variable.
15th May 2017, 6:31 PM
Rrestoring faith
Rrestoring faith - avatar
0
wow. I guess I was missing that in the code I was comparing it to. I guess I need to study up on how functions return values, because I don't quite understand why it didn't work. This has had me frustrated for days. Thanks for the help.
15th May 2017, 6:36 PM
Jacob