Thread: Menu

  1. #16
    Registered User
    Join Date
    Oct 2002
    Posts
    57
    I fixed my first function but now the second one doesnt ever stop ptaking text.

  2. #17
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Krush: Quit with the multiple consecutive postings.... if you've made a mistake, just edit your post.

    >I fixed my first function but now the second one doesnt ever stop ptaking text.
    Post a snippet of code showing your latest changes, and highlighting the problem area.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #18
    Registered User
    Join Date
    Aug 2009
    Posts
    19
    Before I start, I do C++ programming, and haven't spent much time looking at C... after some quick googling, there are some very similar functions in C that will make your life easy.

    Here is the source, though it might require some work, for a C menu... you just have to write the functions that it calls.


    Code:
    char choice;
    int menu;
    bool DONE = FALSE;
    while (DONE == FALSE)
    {
    /*menu text goes here... your options and such, and user input. Make sure that it is INSIDE the while loop...
     this way, every time the menu is called, be it for an incorrect choice, or the previous operation completed, it will show the menu again. */
    menu = int(choice); // this will convert the char to an int, which I will explain in a moment
    
    switch (menu)
    {
    case 049:
    func1();
    break;
    case 050:
    func2();
    break;
    case 051():
    func3();
    break;
    case 052:
    func4();
    break;
    case 113:
    DONE = TRUE;
    break;
    case 081:
    DONE = TRUE;
    break;
    default: printf("Please make a valid selection! \n";)
    DONE = false; //setting Done to FALSE here is so that the loop will run again, bringing the menu back up.
    break;
    }}
    Now, to explain why. I find switch() and the case (choice) system to be easier than if/else, and more reliable. So, the way I do my menus, at least simple ones like this, is convert the choices to ASCII input, then switch them. The variable will get the ascii value of the character input, then plug it into the variable menu, then run the switch. You MIGHT have to remove the '0' from in front of them, my compiler complains about them but others demand the three digit ASCII value. I'm not sure what yours wants, so I included all three digits. If this is the case, when you make a selection, you will be told to enter a valid input, and the loop will run again, no matter what you enter. This menu will repeat itself, even after the function is ran (i believe) until the user chooses to quit. this is done with the boolean variable DONE.

    If you really want to clean it up, you need indentations, and probably some searching on google for the functions used. I would also recommend double checking all of my syntax, as I am not used to C, but am used to C++.

    Good luck!
    Last edited by kalor_alros; 09-01-2009 at 02:40 AM. Reason: Put code in bad places, corrected.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM