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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Ernest022699Connect With a Mentor Commented:
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
 
mapperAuthor Commented:
Thanks...
0
All Courses

From novice to tech pro — start learning today.