Menu

This is a discussion on Menu within the C Programming forums, part of the General Programming Boards category; Can someone plz tell me how to create a menu so that if you type say 1 it will operate ...

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    2

    Menu

    Can someone plz tell me how to create a menu so that if you type say 1 it will operate on segment of code and so on and so forth. And also if you can please tell me why it works that way and such. thanks

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    You should probably read the rules of this board before you post a message. Then you should do a search on the board to find info that has already been written on menus and such. Then when you have some code of your own, if it is not working properly, post it here and someone will likely help you. I would dare say nobody is going to write your program for you though, if you have not even made a reasonable attempt yourself.

    ~/

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    46
    Can someone plz tell me how to create a menu so that if you type say 1 it will operate on segment of code and so on and so forth.
    Print the menu to screen in whatever format you like. Most menus take the form

    1. Option 1
    2. Option 2
    3. Option 3
    4. Exit
    Make a selection:

    One you've printed the menu and informed the user of their choices, read an interactive option that corresponds to the menu choices. For example, the above menu would accept the numbers 1 through 4. Once you have the option, you can use a switch, if/else or function pointer table lookup to execute the correct code.

    The idea is very simple. Try out a few things and see what you can come up with.

  4. #4
    Deleted Account
    Join Date
    Jan 2004
    Posts
    40
    Code:
    #include <stdio.h>
    
    int menu(void);
    void hellofunc(void);
    void goodbyefunc(void);
    
    int main(void)
    {
    	int choice;
    	while ((choice = menu()) != 3) {
    		switch (choice) {
    			case 1: hellofunc(); break;
    			case 2: goodbyefunc(); break;
    			default: printf("Invalid choice.\n");
    		}
    	}
    
    	return 0;
    }
    
    int menu(void)
    {
    	int choice;
    	printf("\n\nMenu\n");
    	printf("1. Say hello.\n");
    	printf("2. Say goodbye.\n");
    	printf("3. Quit.\n>");
    
    	scanf("%d",&choice);
    	return choice;
    }
    
    void hellofunc(void)
    {
    	printf("Hello there.");
    }
    
    void goodbyefunc(void)
    {
    	printf("Goodbye, sir.");
    }
    or something like that.

  5. #5
    Registered User
    Join Date
    Feb 2004
    Posts
    2

    Smile

    thanks for the help. i got the menu working.

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, 09: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

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