>Whats the ideal way to go about this?
Well, you're right -- you should make a separate function. But instead of focusing on just getting the input, perhaps you could do a bit more: call the functions which are actually going to execute what the user wants. The function would no longer need to return what the user entered, because the function itself would be handling everything after the menus, and thus main() would have no need for it.
>I tried a few if statements
Try a 'switch' statement. Much easier.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
>Whats the ideal way to go about this?
Well, you're right -- you should make a separate function. But instead of focusing on just getting the input, perhaps you could do a bit more: call the functions which are actually going to execute what the user wants. The function would no longer need to return what the user entered, because the function itself would be handling everything after the menus, and thus main() would have no need for it.
Except in anideal situation (my opinion of ideal at least):
1) main() calls menu function which returns the menu entry
2) Switch statement (as suggested) will call functions to process each menu selection -- one function per menu selection
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
You'd have to show us the rest of the code that was causing the errors.
Just to simplify things a bit, don't you think you should be doing a toupper on the selection before processing it?
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
You'd have to show us the rest of the code that was causing the errors.
Just to simplify things a bit, don't you think you should be doing a toupper on the selection before processing it?
... or use a switch statement instead of nested if s? It could be cleaner.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
... or use a switch statement instead of nested if s? It could be cleaner.
... which is what I said in my first post.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Yeah, and I referenced your suggestion in my first post.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944