-
March 10th, 2009, 05:30 PM
#1
How To Return to Main()
i have so many functions in my program,what i want to do is, i want to return back to the main() but in somewhere middle of it!.
should i use goto statements?
i tried 'em,it gave some error!
if i should use goto then please explain how to,thanks
-
March 10th, 2009, 05:31 PM
#2
Re: How To Return to Main()
You should design your program so that this isn't necessary, that's how.
-
March 10th, 2009, 05:43 PM
#3
Re: How To Return to Main()
When you return from a function, control returns to the statement right after your call to the function. So, if you call a function from main, you'll return there.
-
March 10th, 2009, 06:41 PM
#4
Re: How To Return to Main()
i want to return to the lines above ,where i call the function,i cant design my program.
i want to return to a menu which is in the main and if the user wants to run the function again then he can select it again from the main
-
March 10th, 2009, 06:49 PM
#5
Re: How To Return to Main()
Originally Posted by arshad115
i want to return to the lines above ,where i call the function,i cant design my program.
i want to return to a menu which is in the main and if the user wants to run the function again then he can select it again from the main
Basically do something like:
Code:
int main( )
{
bool shutdown = false;
while (!shutdown)
{
switch (ShowMenuFunction( )) // returns the selected menu option
{
case 0:
DoMenuOptionZeroFunction( );
break;
case 1:
DoMenuOptionOneFunction( );
break;
case N: // assuming option N is 'exit'
shutdown = true;
break;
};
}
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|