PDA

View Full Version : [Resolved] C programming, menu?




CsRookie
Apr 14, 2011, 09:32 PM
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:



jiminaus
Apr 14, 2011, 09:46 PM
Something like the following pseudo-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.

CsRookie
Apr 14, 2011, 09:58 PM
Something like the following pseudo-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.

Thanks for the quick response, I thought it may be a loop but wasn't sure. Thank you again :apple: