Some suggestions, including the one menu option I forgot earlier - add.
Code:
//basic menu program
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h> //for toupper
int subMenu(char *); //list of the functions prototypes
void addProduct(void);
void viewProduct(void);
void editProduct(void);
void deleteProduct(void);
void addCustomer(void);
void viewCustomer(void);
void editCustomer(void);
void deleteCustomer(void);
int main(void) { //always int main
char pick;
char *wordptr; //char pointer, used to point to and print
char wordP[] = {"Products" }; // one of these words, in
char wordC[] = {"Customers"}; //the sub Menu function
char wordO[] = {"Order"};
int subpick;
printf("\n\n Main Menu\n =========\n\n");
printf(" A. Products\n");
printf(" B. Customers\n");
printf(" C. Orders\n"); //after this, add 2 spaces and print Q to Quit choice
printf("\n pick one [a,b,c]: "); //needs a 'q' to quit added
scanf("%c", &pick);
pick = toupper(pick); //changes lower case letter to upper case letter
if(pick == 'A') //gives the wordptr the right word's address
wordptr = wordP; //the array's name is it's address
else if(pick == 'B')
wordptr = wordC;
else
wordptr = wordO;
printf("\n you chose %s", wordptr);
subpick = subMenu(wordptr);
switch (pick) {
case 'A':
if(subpick == 1) //menu choices logic, grouped by
addProduct(); // Products, Customers, or Order
else if(subpick == 2) //then by Add, View, Edit, Delete
viewProduct(); //functions, below them
else if(subpick == 3)
editProduct();
else if(subpick == 4)
deleteProduct();
break;
case 'B':
if(subpick == 1)
addCustomer();
else if(subpick == 2)
viewCustomer();
else if(subpick == 3)
editCustomer();
else if(subpick == 4)
deleteCustomer();
break; //switch statements use "fall through" logic
case 'C': //so every case should end with the break
break; //line of code. Fall through logic can be very
// Needs a case 'Q': so the user can quit (just a break line will do)
default: //useful, at times.
printf("\n There was an error in the switch code");
} //anything not handled by cases above will
printf("\n\n\t\t\t press enter when ready"); //come to the default case
while((pick = getchar()) != '\n'); //pulls char's from the keyboard buffer
pick = getchar(); //until a newline is reached. This gets one more char
return 0; //from the user. Effectively stopping the console window from
} //closing before you can view it critically.
int subMenu(char *wordptr) {
int subpick = 0;
do {
printf("\n\n %s Menu\n\n", wordptr); //here's our pointer at work
printf(" 1. add\n");
printf(" 2. view\n");
printf(" 3. edit\n");
printf(" 4. delete\n");
printf("\n pick one [1-4]: ");
scanf("%d", &subpick);
}while(subpick < 1 || subpick > 4); //loop condition helps stop bad input from user
return subpick;
}
void addProduct(void) {
printf("\n Enter the new product number: ");
}
void viewProduct(void) {
printf("\n Enter a product number to view: ");
}
void editProduct(void) {
printf("\n Enter a product number to edit: ");
}
void deleteProduct(void) {
printf("\n Enter a product number to delete: ");
}
void addCustomer(void) {
printf("\n Enter the new customer's name: ");
}
void viewCustomer(void) {
printf("\n Enter the customer's name to view: ");
}
void editCustomer(void) {
printf("\n Enter the customer's name to edit: ");
}
void deleteCustomer(void) {
printf("\n Enter the customer's name to delete: ");
}
There's a lot that isn't in here: it doesn't loop back to the main menu, for instance (and it must do that). It also doesn't have any file handlling, or do anything to display, or compute any data, yet. All these little functions, need to be added to substantially.
It's difficult to tell someone, without an example, how to write a menu/sub-menu program. Just saying:
"Well, you use loops to move from one function to the other, then loop back",
is not very enlightening.
It may look much different, but this is your earlier program, with a bit of adornments.