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
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
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.
~/
Print the menu to screen in whatever format you like. Most menus take the formCan 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.
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.
or something like that.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."); }
thanks for the help. i got the menu working.