Resolved C programming, menu?

Discussion in 'Mac Programming' started by CsRookie, Apr 14, 2011.

  1. CsRookie, Apr 14, 2011
    Last edited: Apr 14, 2011

    macrumors newbie

    Joined:
    Apr 13, 2011
    Messages:
    17
    #1
    How would one go about creating a menu for a c program? The menu would allow the user to select where they want to go in the program. For example:

    1)View Inventory
    2)Add Inventory
    3)Remove Inventory
    4)Save
    5)Exit

    Something along those lines and the user would input 1-5 and then it would take them to the next part of the program. How would a menu driven program work? I tried the search but no luck, any links to examples or simple explanation would be greatly appreciated. :apple:
     
  2. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Messages:
    1,448
    Location:
    Sydney
    #2
    Something like the following pseudo-code:

    Code:
    Initialize program
    Loop
      Print menu on screen
      Read menu choice from keyboard
      If menu choice is 1 then do view inventory
      If menu choice is 2 then do add inventory
      (etc.)
      If menu choice is 5 then exit loop
    End loop
    Cleanup program
    
    In terms of implementing this, you'd probably do this all in main, and define separate functions to implement "do view inventory", "do add inventory", etc.
     
  3. macrumors newbie

    Joined:
    Apr 13, 2011
    Messages:
    17
    #3
    Thanks for the quick response, I thought it may be a loop but wasn't sure. Thank you again :apple:
     

Share This Page