Thread: poiner problem in function

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    15

    poiner problem in function

    I am getting this error when the linked list pointer passes through the calc_gross function. Not sure why?
    Code:
    error:
    warning in function calc_gross
    parse error at the end of input
    here is my program:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define OVERTIME_RATE 1.5
    #define STD_WORK_WEEK 40.000
    
    struct employee
    {
    
       	char name[20];      /*name*/
        unsigned long int clock;         /*clock number*/
    	float wage;          /*hourly pay*/
    	float hours;          /*hours worked*/
    	float overtime;       /*overtime hours above 40*/
    	float gross;         /*total pay including any overtime*/
    	
        struct employee *next;
    
    };
    
    
    void header (void)      
    {     
            /* Explain what program is going to do */
    
    	printf ("To find out the gross pay of your employees,\n");
    	printf ("input the name and hours worked at the clock# prompts.\n");
    	printf ("\n");
    }
    
    
    void print_list(struct employee *emp1)
    
    {
            struct employee *tmp; /* tmp pointer value to current node */
            int i = 0;            /* counts the nodes printed          */
    	
        printf ("\n");
    	printf ("__________________________________________________________________________\n");
    	printf ("Employee Name\tClock #\t  Wage\t  Hours\t   OT\t  Gross\n");
    	printf ("__________________________________________________________________________\n");
    		
    		
            /* Start a beginning of list and print out each value               */
            /* loop until tmp points to null  */
            for(tmp = emp1; tmp ; tmp = tmp->next)
            {
                i++;	
                printf ("%s\t%06lu\t%7.2f\t%7.2f\n", tmp->name, tmp->clock, 
         	            tmp->wage, tmp->hours);
         	}
         
          	printf ("\n\n");
    }
    
    void get_hours (struct employee *emp1)
    {
            struct employee *tmp; /* tmp pointer value to current node */
            int i = 0;            /* counts the nodes printed          */
    
            /* Start a beginning of list and print out each value               */
            /* loop until tmp points to null    */
            for(tmp = emp1; tmp ; tmp = tmp->next)
            {
                i++;
                printf("\nFor Employee #%06lu: ", tmp->clock);     
                printf("Enter Hours Worked ");
                scanf ("%f", &tmp->hours);
          }
    
      printf("\n\n");
    }
    
    void calc_gross (struct employee *emp1)
    {
      /*Local Variable Declaration */
    
        struct employee *tmp; /* tmp pointer value to current node */
        int i = 0;            /* counts the nodes printed          */
        float ot_wage; /*Variable for overtime wages only */
        float total; /*Variable used to get the total or regular hours before overtime added */
        
            /* Start a beginning of list and print out each value               */
            /* loop until tmp points to null  */
            for(tmp = emp1; tmp ; tmp = tmp->next)
            {
                i++;
    
    
        /* calculate gross pay including testing for overtime hours using if-else-if statement */
        /* use the DEFINE for STD_WORK_WEEK and OVERTIME_RATE*/
        /* pull the hours collected from get_input with emp_hours[] array*/
    
    		if (tmp->hours > STD_WORK_WEEK)
    		{	(tmp->overtime = tmp->hours - STD_WORK_WEEK);
    			(total = tmp->wage * STD_WORK_WEEK);
    			(ot_wage =  tmp->wage * OVERTIME_RATE);
    			(tmp->gross = ot_wage * tmp->overtime + total);
    			
    		}
    		else if (tmp->hours <= STD_WORK_WEEK)
    		{	(tmp->overtime = 0);
    			(tmp->gross = tmp->wage * tmp->hours);
    		}
    }
    
    int main ()
    {
    
         
           
        char   answer[5];
        int    more_data = 1;   
        char   value;
        char first_name[10], last_name[10];
    
         /* Function to call header. */
      
         header ();
         
         struct employee *current_ptr, /* pointer to current node */
                        *head_ptr;    /* always points to first node */
    
        /* Set up storage for first node */
        head_ptr = (struct employee *) malloc (sizeof(struct employee));
        current_ptr = head_ptr;
    
        while (more_data)
            {
            
                printf("\nFirst Name ");
                scanf ("%s", first_name);
                printf("Last Name ");
                scanf ("%s", last_name);
            
                strcpy(current_ptr->name,  first_name);
                strcat(current_ptr->name,  " ");
                strcat(current_ptr->name,  last_name);
    
              
              printf ("Enter Employee Clock Number: ");
              scanf ("%lu", &current_ptr->clock);
                        
              printf ("Enter Employee Wage: ");
              scanf ("%f", &current_ptr->wage);
                        
            printf("\nWould you like to add another employee? (y/n): ");
            scanf("%s", answer);
    
            /* Ask user if they want to add another employee */
            if (value = toupper(answer[0]) != 'Y')
               {
               current_ptr->next = (struct employee *) NULL;
               more_data = 0; 
               }
            else
               {
               /* set the next pointer of the current node to point to the new node */
               current_ptr->next = (struct employee *) malloc (sizeof(struct employee));
               /* move the current node pointer to the new node */
               current_ptr = current_ptr->next;
               }
    
            }
    
    
        /* Function call to output results to the screen in table format using struct */
    	
       get_hours (head_ptr);  
       
        calc_gross (head_ptr);  
        
        print_list (head_ptr);  
    
    system("PAUSE"); 
    return 0;
    
    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You have a closing brace } missing.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    15
    thats what I thought.. so I put it where I thought and it didnt work.. so I posted.. and then checked my emails and surfed a bit.. then came back.. once I saw your post, I opened my program and wahhllaaa I saw where I needed it..

    I think I needed to get away from it for a minute.. as usual.. its something simple and looking at it too long you just miss it..

    thanks..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM