0

So basically I have:

// FUNCTION
double function(yadee_yada)
if (input < 0)
{
return 0;
}
else {
return something; 
//code
}
// END FUNCTION


//MAIN
int main
{
int menu;
int input;

do {
cout << "Press 1, 2 or 3 (3=quit program).";
cin >> menu;

switch (menu)
{
case 1:
cout << "input 1-5.";
cin >> input;

//CALL FUNCTION (based on "input")

break;

case 2:
//CODE FOR MENU OPTION 2
case 3:
return 0; //QUIT
}
}while(menu != 3)
return 0;

Hope that makes sense. I can post the real code if neeeed be, but I feel like I have a pretty basic question. So when you hit a "break" in one of the switch statements, it goes back to the main menu where you pick option 1, 2, or 3. I want to be able to go to that same menu from within the called function in case the input is less than 0. I tried "return 0;", but it literally just returns the numerical value "0". I tried "break;", but it said I can only use breaks in loops and switch statements. :[

Is there a way to get back to that menu in "main" from a function without putting code in main itself? Thanks!

2
Contributors
1
Reply
17
Views
3 Years
Discussion Span
Last Post by Banfa
0

You will need code in your main function and you will need your other functions to return either a status or a sentinal value that can be tested in main to determin if the execution path needs to return to the start of the switch statement.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.