Thread: Retail Management - the 3rd split

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

    program please

    hi, can someone please post a working code for this program. thanks please. having touble big time with this program. please.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Doubtful. We're not here to build your programs, we're here to help you.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    3
    Code:
      
    #include <stdio.h>
    #include <stdlib.h>
    
    #define MAX_TBL_SIZE 30
    #define MIN_STOCK_LEVEL 10
    #define MAXSTRING 100
    
    int count, stock[MAX_TBL_SIZE], input_item_id[MAX_TBL_SIZE], input_stock[MAX_TBL_SIZE]; float Price[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 Price[MAX_TBL_SIZE]);
    void CURRENTSTATUS (int ItemId[count], int Stock[count], int Price[count], char Sufficient);
    
    int main(void) {
    	char file_name[MAXSTRING];
    	char *inputfile, *outputfile;
    	int num, r, c;
    	int ActionCode, ItemId, Stock, Price, Sufficient, qty_sold, qty_new,input_item_id, unit_price;
    	FILE *ifp; 
    	FILE *ofp;
    	inputfile = (char *) malloc (25);
     
    	fprintf(stderr, "Enter the name of the input file: \n");  //retail.txt
    	scanf("&#37;s", inputfile);
    //	printf("%s",inputfile);
    	//fprintf(outputfile, "num = %d\n", num);
    	ifp = fopen(inputfile, "r");
    	
    	if(ifp==NULL) {
    		printf("Error: can't open file.\n");
    		return 1;
    	}
    	else {
    		printf("File opened successfully.\n");
    	}
    	ofp = fopen(outputfile, "w");
    	//system("PAUSE");
    system ("pause");	
    	return 0;
    }   
          
    void input(FILE *ifp, int input_item_id[count], int input_stock[count], int c, float Price[count])
    {
       while(input_item_id[count] != 0 && input_stock[count] != 0 
       && Price[count] != 0)
             {
             fscanf(ifp, "%d", &input_item_id[count]);
             fscanf(ifp, "%d", &input_stock[count]);
             fscanf(ifp, "%f", &Price[count]);
    
          count++;
             } 
    
    
    
    void ActionCode(int *);{
    int number=1;
          switch (number)
          {
             case 1:
                {
    
                void CURRENTSTATUS (int input_item_id[count], int Stock[count], int Price[count], char Sufficient)
                   {                   
                   printf("CURRENT STATUS\n");
                   printf("Id\t Stock\t Price\t Sufficient\n");
                   printf("%d\t%d\t%.2f\t%c\n", input_item_id, Stock, Price,Sufficient); 
                   }
                }   
                break;
                            
             case 2:
                {
                if(input_stock[count] == 0);
                     {
                     printf("There is no item with id %d.\n", input_item_id[count]);
                     }
                }     
                break;
    
             case 3:
                {  
                printf("After sale, there are %d items with id %d.\n",stock[count], input_item_id[count]);
             
                   if(stock[count] < MIN_STOCK_LEVEL)
                   {
                   printf("This product needs to be reordered.\n");
                   }
                }
                break;    
             
             case 4:  
                {
                printf("After purchase, there are %d items with id %d.\n", 
                stock[count],input_item_id[count]); 
                
                   if(stock[count] < MIN_STOCK_LEVEL)
                   {
                   printf("This product needs to be reordered.\n");
                   }
                   }
                break;
    
             case 5:
                {  
                   printf("Items to be reordered\n");
                   printf("%d\n", input_item_id[count]);
                }
                break;
                
                
             case 6:
                {
                if  (stock[count] <= 1)
                printf("Lowest stock: Only %d items left with id %d.\n", 
                stock[count], input_item_id[count]);
                printf("URGENT ORDER - this product needs to be re-ordered immediately\n");
                }
                break;
                 
                
                        
             case 7:
                {
                Price[count] += stock[count] * Price[count];
                printf("Total price of all the items: $.2f\n", Price[count]);
                }
                break;
                
             case 8:
                {  
                printf("Good Bye!\n");
                }
                break;
           }
    }
    }

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    There are some serious errors in this code. Not to mention probably a lot of run-time bugs, as well...

    Quote Originally Posted by jiljax86 View Post
    Code:
      
    int main(void) {
    	/* ... */
    
    	//system("PAUSE"); /* C uses /* */ style comments, not //. Dunno if // works in C */
    	/* main does not call input nor ActionCode. What's the point of having those functions if they're never called? */
    system ("pause");	
    	return 0;
    }   
          
    /* Fatal error: arrays must be constant.
    count is not constant.
    Declare count as a const int (if that works in C, I don't know) or make it a define). */
    void input(FILE *ifp, int input_item_id[count], int input_stock[count], int c, float Price[count])
    /*...*/
    void ActionCode(int *);{ /* Function definitions does not use a semicolon. Remove the ; before the brace */
    /* What's the point in taking an argument if it's not going to be used? */
    /* What's the point in switching a value you've just initalized to 1? */
    int number=1;
          switch (number)
          {
             case 1:
                {
    		/* Local function declarations are illegal. Move it out of the functiom. */
                void CURRENTSTATUS (int input_item_id[count], int Stock[count], int Price[count], char Sufficient)
                   {                   
                   printf("CURRENT STATUS\n");
                   printf("Id\t Stock\t Price\t Sufficient\n");
                   printf("&#37;d\t%d\t%.2f\t%c\n", input_item_id, Stock, Price,Sufficient); 
                   }
    /*...*/
    Aside from all that, you also keep a lot of global variables which is a bad thing too. Make them local in main and them around through arguments.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You'll need to change this part, to something like this:
    Code:
    void ActionCode(int number ) {  
    
          switch (number)
          {
             case 1:
                {
    etc.
    So the "action code number is supposed to give the user info on the number of that item in stock, by looking it up in the file, and printing out the info?

    Is the ActionCode function the only one that doesn't work?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Retail Management
    By keelhauled in forum C Programming
    Replies: 21
    Last Post: 11-10-2007, 03:11 PM
  2. split file
    By andriss in forum C Programming
    Replies: 4
    Last Post: 10-18-2006, 03:47 PM
  3. Split int variable
    By Jas11 in forum C++ Programming
    Replies: 4
    Last Post: 03-28-2005, 05:06 PM
  4. CString split function ?
    By eXistenZ in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2005, 10:25 AM
  5. Memory management
    By CompiledMonkey in forum C++ Programming
    Replies: 9
    Last Post: 12-19-2003, 11:41 AM