Thread: Retail Management

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    11

    Retail Management

    Hey everyone,

    Have an assignment to create a retail management system using arrays.

    I guess what I need help on is with writing arrays and fuctions that would modify them.

    I know there are people on this board who are in my same class so if yall have any help or coded any bit of it that would be great, I havent started yet, but as soon as I do I'll post my code up.

    Thanks

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The idea would be for you to post your code and from that ask what you have problems with. We aren't here to do your assignments for you, naturally, so that's the way things work around here...

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    5
    I'm one of those in your class. I could use some help on a few things, but I also have some of it down. You can PM me and we can work together, or post some of your code and I can try and help you and vice versa.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you have some code, and some questions, by all means post 'em up, asap. "Retail Management" with arrays is extremely non-specific.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    11
    I'm having trouble with the coding for the imput file, this is what I got, it gives me an error saying ifp is undeclared.

    Code:
    void input(FILE ifp, int input_item_id[counter], int input_stock[counter], float UnitPrice[counter]){
       while(input_item_id[counter] != 0 && input_stock[counter] != 0 
       && UnitPrice[counter] != 0){
     
             fscanf(ifp, "%d", &input_item_id[counter]);
             fscanf(ifp, "%d", &input_stock[counter]);
             fscanf(ifp, "%f", &UnitPrice[counter]);
    
          counter++;
    Okay nevermind I got that problem fixed, I ddint have the file ifp declared in both places, now i have a problem with it saying "incompatible type for argument 1 of `fscanf'"
    Last edited by keelhauled; 11-10-2007 at 12:31 PM.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, and where is ifp declared? It isn't in the code you posted. All variables must be declared. If you haven't done so, then do so. But avoid global variables, if you can.

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    11
    I declared ifp, see my edit above, now my problem is getting incompatible type for argument 1 of fscanf as well as fgetc in this code
    Code:
     
    void input(FILE ifp, int input_item_id[counter], int input_stock[counter], float UnitPrice[counter]){
       while(input_item_id[counter] != 0 && input_stock[counter] != 0 
       && UnitPrice[counter] != 0){
     
             fscanf(ifp, "%d", &input_item_id[counter]);
             fscanf(ifp, "%d", &input_stock[counter]);
             fscanf(ifp, "%f", &UnitPrice[counter]);
    
          counter++;
    } 
    
    while ((c=fgetc(ifp)) != EOF) {

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > void input(FILE ifp
    void input(FILE *ifp

    Also, as I explained to one of your colleagues, you're incrementing the counter THEN comparing to see if the last read values where 0 0 0
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    fopen, etc returns a FILE*. fscanf and fgets takes a FILE* as argument, not FILE.

  10. #10
    Registered User
    Join Date
    Oct 2007
    Posts
    11
    Quote Originally Posted by Salem View Post
    > void input(FILE ifp
    void input(FILE *ifp

    Also, as I explained to one of your colleagues, you're incrementing the counter THEN comparing to see if the last read values where 0 0 0
    Not sure what you mean by incrementing the counter then...

    Thanks for the help though, its finally coming along.

    Now I have a problem in my switches
    Code:
     void ActionCode(int *);
          switch (ActionCode){
             case 1:
                {
                void CURRENTSTATUS (int ItemId[counter], int Stock[counter], 
                int UnitPrice[counter], char Sufficient){
                                       
                   printf("CURRENT STATUS\n");
                   printf("Id\tStock\tPrice\tSufficient\n");
                   printf("%d\t%d\t%.2f\t%c\n", ItemId, Stock, UnitPrice, 
                   Sufficient);
    it says that my switch quantity is not an integer, can someone explain that? Thanks.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Catch must use an integer value (constant):
    Code:
    int anint = 5;
    switch(something)
    {
    	case anint: // BAD! Can't use integers in switches!
    		break;
    }
    Code:
    #define anint 5
    // OR the following:
    // const int anint = 5;
    switch(something)
    {
    	case anint: // OK, because it's a define, hence translates to case 5:
    		break;
    }
    Though it will work if your int is constant. The compiler will know that the value will never change from what it was initialized with and can translate the function hence, I believe.
    Last edited by Elysia; 11-10-2007 at 01:17 PM.

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    ActionCode is the name of a function, so not really a "integer based type", is it?

    I also posted earlier, that defining functions inside other functions is very special things, and most compilers don't allow it. In this case, it's A) completely unnecssary and B) not doing what you expect it to do, since [at least if your code is similar to what was posted earlier] it is also never called. Move the function out of there, and call it in the code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    Code:
    #define anint 5
    }
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Oops, my bad!

  15. #15
    Registered User
    Join Date
    Oct 2007
    Posts
    11
    Ok, this is what I have as of now.

    Code:
    #include <stdio.h>
    #define MAX_TBL_SIZE 30
    #define MIN_STOCK_LEVEL 10
    #define MAXSTRING 100
    
    int counter, stock[MAX_TBL_SIZE], input_item_id[MAX_TBL_SIZE], input_stock[MAX_TBL_SIZE]; float UnitPrice[MAX_TBL_SIZE];
    void ActionCode(int *);
    void input(FILE *ifp,int input_item_id[MAX_TBL_SIZE], int input_stock[MAX_TBL_SIZE], int c, float Unitprice[MAX_TBL_SIZE]);
    void CURRENTSTATUS (int ItemId[counter], int Stock[counter], int UnitPrice[counter], char Sufficient);
    
    int main(void) {
    
       char file_name[MAXSTRING];
       int num, r, c;
       int ActionCode, ItemId, Stock, UnitPrice, Sufficient, qty_sold, qty_new,
       input_item_id, unit_price;
       FILE *ifp;
       FILE *ofp;
     
       fprintf(stderr, "Enter the name of the input file: \n");
       fscanf(ifp, "%d", &num);
       fprintf(ofp, "num = %f\n", num);
       ifp = fopen("file_name", "r");
       system("PAUSE");
       return 0;
    }   
    
    //Obtaining action code and use switch to process action
    
    //Void function obtaining imput file
    void input(FILE *ifp, int input_item_id[counter], int input_stock[counter], int c, float UnitPrice[counter]){
       while(input_item_id[counter] != 0 && input_stock[counter] != 0 
       && UnitPrice[counter] != 0){
     
             fscanf(ifp, "%d", &input_item_id[counter]);
             fscanf(ifp, "%d", &input_stock[counter]);
             fscanf(ifp, "%f", &UnitPrice[counter]);
    
          counter++;
    } 
    
    while ((c=fgetc(ifp) != EOF)) {
    
    /* Use a switch statement instead */
    void ActionCode(int *);
    int number=1;
          switch (number){
             case 1:
                {
                void CURRENTSTATUS (int input_item_id[counter], int Stock[counter], 
                int UnitPrice[counter], char Sufficient){
                                       
                   printf("CURRENT STATUS\n");
                   printf("Id\tStock\tPrice\tSufficient\n");
                   printf("%d\t%d\t%.2f\t%c\n", input_item_id, Stock, UnitPrice, 
                   Sufficient); 
                }
                break;
                            
             case 2:
                if(input_stock[counter] == 0);
                printf("There is no item with id %d.\n", input_item_id[counter]);
                break; 
    
             case 3:
                printf("After sale, there are %d items with id %d.\n", 
                stock[counter], input_item_id[counter]);
             
                   if(stock[counter] < MIN_STOCK_LEVEL){
                   printf("This product needs to be reordered.\n");
                   }
                break;    
             
             case 4: /* input_item_id == 1 */ 
                printf("After purchase, there are %d items with id %d.\n", 
                stock[counter],input_item_id[counter]); 
                
                   if(stock[counter] < MIN_STOCK_LEVEL){
                   printf("This product needs to be reordered.\n");
                   }
                break;
    
             case 5:
    
                   print("Items to be reordered\n");
                   print("%d\n", input_item_id[counter]);
                   }
                   break;
                
                
             case 6:
                if  (stock[counter] <= 1)
                printf("Lowest stock: Only %d items left with id %d.\n", 
                stock[counter], input_item_id[counter]);
                printf("URGENT ORDER - this product needs to be re-ordered immediately\n");
                break;
                 
                
                        
             case 7:
                UnitPrice[counter] += stock[counter] * UnitPrice[counter];
                printf("Total price of all the items: $.2f\n", UnitPrice[counter]);
                break;
                
             case 8:
                printf("Good Bye!\n");
                break;
          }  
       }        
    }
    Sorry if you told me a suggestion and I did it wrong, I try to understand best I can but all this stuff is so confusing to me. Right now if I try to compile this I get an error saying linker error undefined reference to print.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Retail Management - the 3rd split
    By jiljax86 in forum C Programming
    Replies: 4
    Last Post: 11-11-2007, 06:38 AM
  2. DirectX dll Final Debug and Final Retail
    By hdragon in forum Tech Board
    Replies: 0
    Last Post: 11-15-2005, 09:46 PM
  3. Memory management
    By CompiledMonkey in forum C++ Programming
    Replies: 9
    Last Post: 12-19-2003, 11:41 AM
  4. FreeBSD User Management
    By frenchfry164 in forum Tech Board
    Replies: 6
    Last Post: 09-11-2003, 01:31 AM
  5. heap memory management
    By jdinger in forum C++ Programming
    Replies: 4
    Last Post: 04-27-2002, 10:23 PM