// This C program named menu.c is to demonstrate operation of a Menu // Author ... (type here your name) // Date ... (type here the current date) // For ... (institution, course, purpose) //--------------------------------------------------------------------------- #include //Handles the keyboard input and screen output #include //Handles DOS system commands ("cls", "pause") void main() { //This part declares variables used by the program int reply=0; //Reply to manu chaice int i, items = 3; //Loop counter, loop limit //This part displays the menu items system("cls"); printf("Welcome to MENU program!"); while (reply < items) { printf("\n\nHere are menu options that this program offers:"); //This part displays menu options for (i = 1; i < items; i++) { printf ("\n%d. Option number %d", i, i); } printf ("\n%d. (or %d, ..., etc.) EXIT program.", items, (items+1)); printf ("\n"); // Changes the line printf("\nTo terminate choose the option %d, or higher!", items); printf("\nPlease choose the item to run (e.g. 1, ..., %d) ", items); scanf("%d", &reply); // Inputs your reply printf("Your choice was option number %d", reply); //Displays the option //Completes the processing for subsequent options if (reply == 1) { //Here complete actions for menu option number 1 printf ("\nOption number 1 was executed here!"); } if (reply == 2) { //Here complete actions for menu option number 2 printf ("\nOption number 2 was executed here!"); } // ... (continue with options) if (reply >= items) { //This completes actions for the option PROGRAM EXIT printf (" which terminates this program!"); } if (reply < 1) { //Here is the "wrong reply" error message printf ("\nChoice %d is out of range (retype 1, ..., %d).",reply, items); } } //The final displays printf ("\n\nThank you for using this program. Good bye!"); printf ("\n"); // Changes the line system("pause"); // DOS "Pause" command (for user to look at results) }