+ 1

How do I get my function to return a value that tells a do while loop in another function to continue or not?

https://code.sololearn.com/cnROcf4p641N/?ref=app I'm trying to offer the user the option to return to the main menu after using the first function. I have a do while loop in the menu function that is supposed to check for the value of the return and decide whether or not to proceed. It all looks right to me and compiles, but when I try to actually use it the program terminates. Any suggestions are appreciated. Full code attached.

11th May 2017, 12:19 AM
Jacob
5 Réponses
+ 5
1. You dont need to pass menuReturn to the functions: int multiply(); int displayHello(); as you are not really doing anything with the number from the main menu in the functions (just getting new user input, so a new variable in the functions is fine here) 2. you didn't return a value from displayHello We need a return value to take action on 3. You need to store the return value back into menuReturn at 28 and 30. see (2) This seems to work now. https://code.sololearn.com/c3ZKX0pJ0qsf/#cpp
11th May 2017, 1:48 AM
jay
jay - avatar
+ 1
I use another compiler so inputs aren't such a pain
11th May 2017, 12:39 AM
Jacob
+ 1
Saved the day second time today, Jay. I might need to keep you around.
11th May 2017, 2:19 AM
Jacob
0
lines 59 - 63 and 21 - 33 seem to be my problem areas.
11th May 2017, 12:21 AM
Jacob
0
Heres some code to help you get started, it sounds like you just need one extra layer to the code written below. Keep in mind this program has you in a while loop and is waiting for the response "F" to take you out of the while loop. Once it recieves the response "F" it takes you back to main. Because there is nothing else left to the main program you exit. Hope this helps. Stay curious. #include <iostream> using namespace std; bool cont = true; void con(string x){ if (x == "F"){ cont = false; } else if (x == "T") { cont = true; } } int main(){ while(cont == true){ string continuing; cout << "would you like to continue" << endl; cin >> continuing; con(continuing); } }
11th May 2017, 10:18 PM
Thomas W. Smith
Thomas W. Smith - avatar