Menu System using switch and case.

This is a discussion on Menu System using switch and case. within the C Programming forums, part of the General Programming Boards category; when you guys want to generate a console based menu system, would you always use "case" statements ? doesnt anybody ...

  1. #1
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66

    Menu System using switch and case.

    when you guys want to generate a console based menu system, would you always use "case" statements ? doesnt anybody use "if" statements for menu's ? i made some with "if" statements, and i am wondering if i should stop doing so incase its a bad inefficient non standard way of generating menus.

    thanx in advance..

  2. #2
    Registered User stormbringer's Avatar
    Join Date
    Jul 2002
    Posts
    90
    well, i was usings if's but then changed to cas statements. i don't know about efficiency or similar topics (but i don't think the one is more efficient than the other). i just feel that case statements make the code more readable.

    stormbringer

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I think it depends on what suits your needs. Both switch and if statements are good in their own right.

    There was a discussion here where I showed an example of using structs and functions pointers to build a menu, display it and access the users choice. I thought it fitted well in the app I was writing, because it allowed for sub-menus nice and easily. But the code is over complicated if all you want to do is display one simple menu.

    Pay your money, and take you choice!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    I never use if statements for building menu's, but that my personal choice.
    Normally I use the switch statement or, if the menu's are getting too large, array's of menu items (something like Hammer's example).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  3. ascii rpg help
    By aaron11193 in forum C Programming
    Replies: 18
    Last Post: 10-29-2006, 01:45 AM
  4. Xmas competitions
    By Salem in forum Contests Board
    Replies: 88
    Last Post: 01-03-2004, 01:08 PM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 06:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21