order system help!

This is a discussion on order system help! within the C Programming forums, part of the General Programming Boards category; Hey guys, having trouble getting started on a task i have. The task is to create a customer order system ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    13

    order system help!

    Hey guys, having trouble getting started on a task i have.

    The task is to create a customer order system for an oil company who sells oil products to its customers. The customers are companies using the oil products in their machines or in their manufacturing processes.
    basic requirements:
    1. Product file with price and discount information. It should be possible to do
    some basic maintenance of the file.
    2. Customer file with customer information like customer number, name, adress etc.
    It should be possible to do some basic maintenance of the file.
    3. You should be able to enter customer orders and save them to a file, using the
    stored product and customer information.
    The program should be menu driven.



    my foughts is to make a menu with 3 options as the 3 above. Then make 3 functions that will start if you choose it from the menu. i dont know if thats the right way to go but atleast ive said something about how im thinking. Im not that skilled on C yet.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    //put in 3 functions...:/
    
    its not much but it all ive got this far. if anyone wanna help me sort this one out i would be forever greatful. 
    
    void main()
    {
    
    	char pick;
    printf(" Menu\n ===\n");
    printf("A. Products\n");
    printf("B. Customer\n");
    printf("C. Order\n");
    
    printf("pick one: ");
    
    scanf("%c", &pick);
    switch (pick)
    { case 'A': printf("The function for the Products");
    break;
    case 'B': printf("The function for the Customer");
    	break;
    case 'C': printf("The function for the Order");
    	break;
    
    default: printf("Wrong type in\n");
    	
    	break; }
    }

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'd think you'd want 4 functions for each of the files, in a sub-menu

    1) View
    2) Edit
    3) Delete
    4) Quit this menu (from the main menu, quit the program)

    naturally, I'd use structs as my data records. One for customers, another for products, a third for orders.

    For reasons I won't go into, using numbers is easier to program than using char's.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    13
    Quote Originally Posted by Adak View Post
    I'd think you'd want 4 functions for each of the files, in a sub-menu

    1) View
    2) Edit
    3) Delete
    4) Quit this menu (from the main menu, quit the program)

    naturally, I'd use structs as my data records. One for customers, another for products, a third for orders.

    For reasons I won't go into, using numbers is easier to program than using char's.
    Ok il get ya. but now i cant get the sub-menu right.. can someone take a look and correct it?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    
    void main()
    {
    
    	char pick;
    printf(" Menu\n ===\n");
    printf("A. Products\n");
    printf("B. Customer\n");
    printf("C. Order\n");
    
    printf("pick one: ");
    
    scanf("%c", &pick);
    switch (pick)
    { case '1':
    
    
    char submenu1;
    printf(" Menu\n ===\n");
    printf("1. view\n");
    printf("2. edit\n");
    printf("3. delete\n");
    
    printf("pick: ");
    
    scanf("%c", &submenu1);
    switch (submenu1)
    { case 'a': printf("you choose wiew");
    
    }
    
    
    
    
    
    
    
    break;
    case 'B': printf("The function for the Customer");
    	break;
    case 'C': printf("The function for the Order");
    	break;
    
    default: printf("Wrong type in\n");
    	
    	break; }
    }

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Your main menu offers choices A, B, and C, yet you go into the submenu when the user types 1?

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    13
    Quote Originally Posted by tabstop View Post
    Your main menu offers choices A, B, and C, yet you go into the submenu when the user types 1?

    ye got a error saying that A B or C was used already..

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you change the '1' in your code to 'A' you don't get any such error.

  7. #7
    Registered User
    Join Date
    Oct 2009
    Posts
    13
    Quote Originally Posted by tabstop View Post
    If you change the '1' in your code to 'A' you don't get any such error.
    Nice ty!

    but i cant make a chooise in the sub-menu. the program is shutting off if i push any button after getting to sub-menu.

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well, the program is finished, since nothing happens after that.

  9. #9
    Registered User
    Join Date
    Oct 2009
    Posts
    13
    Quote Originally Posted by tabstop View Post
    Well, the program is finished, since nothing happens after that.
    what about the sub-menu. why does the program ignore the choises, why dosnt i get to pick one of the sub's options?

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by casper87 View Post
    what about the sub-menu. why does the program ignore the choises, why dosnt i get to pick one of the sub's options?
    Probably because your scanf line should look like
    Code:
    scanf(" %c", &submenu1);
    instead.

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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.
    Last edited by Adak; 10-22-2009 at 02:50 PM.

  12. #12
    Registered User
    Join Date
    Oct 2009
    Posts
    13
    Quote Originally Posted by Adak View Post
    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 *);
    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) {  
    
      char pick; 
      char *wordptr;
      char wordP[] = {"Products" };
      char wordC[] = {"Customers"};
      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");
    
      printf("\n     pick one [a,b,c]: ");
    
      scanf("%c", &pick);
      pick = toupper(pick);
    
      if(pick == 'A')
         wordptr = wordP;
      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)
            addProduct();
          else if(subpick == 2)
            viewProduct();
          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;
        case 'C':
              
          break;
        default:
          printf("\n There was an error in the switch code");
      }       
      printf("\n\n\t\t\t     press enter when ready");
      while((pick = getchar()) != '\n');
      pick = getchar();
      return 0;
    }
    int subMenu(char *wordptr) {
      int subpick = 0;
        
      do {  
      printf("\n\n        %s Menu\n\n", wordptr);
      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);
    
      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: ");  
    }
    Ty m8 this will give me some sight how to think when ive build it! really nice
    u dont think u could comment out some of the code and tell me what they do?
    Last edited by casper87; 10-22-2009 at 11:53 AM.

  13. #13
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Added comments to the program in post #11.

    Forgot to mention that the whole main menu part of the code, will need to be inside a do while or while loop, which is not there yet.

    These work like this:
    Code:
    pick = 'a';  //(anything but 'q') this "primes the pump" for the do loop
    do {
       //all the main menu code goes inside this loop
       //including the display, the switch statement
       //etc.
       
    }while(pick != 'q');

  14. #14
    Registered User
    Join Date
    Oct 2009
    Posts
    13
    Quote Originally Posted by Adak View Post
    Added comments to the program in post #11.

    Forgot to mention that the whole main menu part of the code, will need to be inside a do while or while loop, which is not there yet.

    These work like this:
    Code:
    pick = 'a';  //(anything but 'q') this "primes the pump" for the do loop
    do {
       //all the main menu code goes inside this loop
       //including the display, the switch statement
       //etc.
       
    }while(pick != 'q');
    ive been trying to add a "q" quit chooise to my menu now but allways gets error, guess il dont place the "do loop" right.

    but i was now trying to add a simple save to textfile function to the program.


    aint it right that i should place the code like this:


    Code:
     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) {
      char addP[30];
      FILE*outfile;
      outfile = fopen("products.txt", "w");
    	  printf("\add product:");
    	  gets(addP);
    	  while(addP[0]!='\0')
    	  {
    		  fputs(addP, outfile);
    		  fprintf(outfile, "\n");
    
    		  printf("add product:");
    		  gets(addP);
    	  }
    	  fclose(outfile);
    }
    
    }
    void viewProduct(void) {
      printf("\n     Enter a product number to view: ");
    }
    void editProduct(void) {
      printf("\n     Enter a product number to edit: ");

  15. #15
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    That code looks unchanged. I don't see a 'q' to quit, anywhere. Also, that's the sub menu, not the main menu, so it's not the menu I was referring to.

    Last time I ran your program, you could make a choice from the main menu, and then make a choice from the sub menu. But you couldn't loop back to the top of the main menu, because there was no loop coded up for the main menu code, in main(). The whole program just ended.

    It won't be happy until it gets one.
    Last edited by Adak; 10-26-2009 at 06:59 AM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Smooth walking on tile based map system
    By abraham2119 in forum C Programming
    Replies: 8
    Last Post: 07-10-2009, 11:33 AM
  2. intereacting with fily system in c
    By KBriggs in forum C Programming
    Replies: 8
    Last Post: 06-26-2009, 03:28 AM
  3. Laplace Expansion
    By Leojeen in forum C Programming
    Replies: 7
    Last Post: 10-29-2008, 12:26 AM
  4. Best way to have an list of indices which changes order
    By laertius in forum C Programming
    Replies: 5
    Last Post: 09-29-2008, 01:45 AM

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