• C

Using Switch and Functions...

I am developing a program that prints an options menu - the menu displays options and each option has a corresponding value - I want to use the SWITCH for each case statement.  My questions is:

I will have functions do the grunt work for each menu option -
like:

Find video(s)
Check out video(s)
Return video(s)
Find all videos out to a customer
Add a new video(s)
Print inventory list (sorted by...)

Each option above with have a function do the work - would the function be embedded in the case expression?  If so, what would that look like?

Thanks,

Mapper
mapperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ernest022699Commented:
Yes, the function call would be in the switch ... case.  You should use #defined constants for each option.  Here's approximately what it would look like:

int retval;

switch (UserInput)
  {
  case FIND_VID:
    retval = func_find();
    break;

  case CHECK_OUT:
    retval = func_checkout();
    break;

  case RETURN_VID:
    retval = func_retvid();
    break;
....
  default:
    /* error handling goes here */
    retval = ERROR_VALUE;
    break;
}

return(retval);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mapperAuthor Commented:
Thanks...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.