OK, I missed something pretty big, I'm still getting the same error, but I missed a couple things that change a lot of the assignment so I'm going to repost the code here now as I have it. I still have the same errors, you're right though, I had main all messed up. I probably still do, but looking at a couple of the class things, I'd say it's a lot better than it was. Still something is missing though and I'm not sure what.
(start code) #include <stdio.h> #define DATA_SETS 5 #define STD_HOURS 40.0 #define OT_RATE 1.5 /****************************************/ /* Structure Declarations */ /****************************************/ struct employee /* Structure to store associate data */ { char name[20]; /*employee names*/ long id_number; /* Member: Stores Clock ID Number */ float wage; /* Member: Stores hourly wage */ float hours; /* Member: Stores number of hours worked */ float overtime; /* Member: Stores number of overtime hours worked */ float gross; /* Member: Stores gross pay */ struct employee *next; }; /************************************************************************/ /* Function: input_hours_worked */ /* */ /* Purpose: Obtains input from user, the number of hours worked for */ /* each employee based on clock number. The number of */ /* hours worked are passed back to 'main', where they are */ /* assigned to the array hours_worked. */ /* */ /* Parameters: n - Data set #. */ /* clock - Employee's clock number */ /* */ /* Returns: hours: The number of hours worked. */ /* */ /************************************************************************/ float input_hours_worked ( int n, int clock ) { /* Local Declarations */ float hours; /* Number of hours worked by employee */ float hours_in_a_week = 168.0; /* Max hours in a work week */ printf ( "\n" ); printf ( "Data Set #%i\n", n + 1 ); printf ( "Clock Number: %06i\n", clock ); printf ( "Enter Hours Worked: " ); scanf_s ( "%f", &hours ); /* Read in the number of hours worked */ /* Test for user error */ if( ( hours >= 0.0 ) && ( hours < hours_in_a_week ) ) return hours; /* Return the number of hours worked */ else return ( -1.0 ); /* Return Error */ } /* End of input_hours_worked function */ /************************************************************************/ /* Function: calculate_overtime_hours */ /* */ /* Purpose: Calculate the amount of overtime worked based on a 40 */ /* hour work week. */ /* */ /* Parameters: hours - Number of hours worked */ /* */ /* Returns: A value equal to the number of overtime hours worked. */ /* If no overtime was worked, then 0.0 is returned. */ /* */ /************************************************************************/ float calculate_overtime_hours ( float hours ) { /* Calculate Overtime Hours */ if( hours > STD_HOURS ) return ( hours - STD_HOURS ); /* Return the amount of overtime worked */ else return ( 0.0 ); /* Return that no overtime was worked */ } /* End calculate_overtime function */ /************************************************************************/ /* Function: calculate_gross_pay */ /* */ /* Purpose: Calculate the total gross pay based on the amount of */ /* time that was worked. This includes overtime pay, if */ /* applicable. */ /* */ /* Parameters: ot - Overtime hours worked */ /* hours - Regular hours worked */ /* wage_per_hour - Hourly wage for employee */ /* */ /* Returns: Returns a value that is equal to the gross pay due to */ /* the employee. */ /* */ /************************************************************************/ float calculate_gross_pay ( float ot, float hours, float wage_per_hour ) { if( ot > 0 ) return ( wage_per_hour * ( STD_HOURS + ( ot * OT_RATE ) ) ); else return ( wage_per_hour * hours ); } /* End calculate_gross_pay function */ /************************************************************************/ /* Function: display_wage_data */ /* */ /* Purpose: To display all employee information to the screen. */ /* */ /* Parameters: worker - Array of structures with all employee info */ /* size - number of array elements to process */ /* */ /* Returns: Nothing. */ /* */ /************************************************************************/ void print_list(emp1) 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 (remember null is 0 or false) */ void display_wage_data ( struct employee worker[], int size ); { /* Local Declarations */ int n; /* loop and array index */ /* Print out header */ printf ( "\n\n" ); printf ( "---------------------------------------------------\n" ); printf ( "Clock#\t Wage Hours\t OT\t Gross \n" ); printf ( "---------------------------------------------------\n" ); /* Print data for each employee */ for( tmp=emp1; tmp; tmp = tmp->next) { printf ( "%06i\t%5.2f\t%4.1f\t%4.1f\t%6.2f\n", tmp->id_number, tmp->wage, tmp->hours, tmp->overtime, tmp->gross ); } /* End for loop */ } /* End display_wage_data function */ /************************************************************************/ /* Function: error_check */ /* Purpose: To report any error to the user. */ /* */ /* Parameters: hours - Hours entered by user */ /* */ /* Returns: Nothing. */ /* */ /************************************************************************/ void error_check (float hours) { /* see if error condition on hours exists */ if( hours == -1.0 ) { printf ( "An invalid entry has been made.\n" ); printf ( "Please start over.\n" ); exit (1); } /* End of if statement */ } /* End error_check function */ /*****************/ /* MAIN */ /*****************/ main() { char answer[80]; int more_data = 1; char value; /* Local Declarations */ struct employee *current_ptr, = /* Array of structures storing */ /* all associate data */ *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) { /* prompt user to enter the employee's name, id #, and wage */ /* Note that name is an array name, and id and wage are long */ /* int and float, so they need the &. */ printf ("\n"); printf ("Please enter the employee's name: "); scanf ("\n"); gets (pointer->name); printf ("\nPlease enter %s's id number: ", pointer->name); scanf ("%ld", &pointer->id_number); printf ("\nPlease enter %s's wage: ", pointer->name); scanf ("%f", &pointer->wage); printf ("\n"); printf("Would 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; } }; int n; /* Loop Counter */ /* Introduce User to program */ printf ( "WAGE CALCULATOR\n" );printf ( "Please input the number of Hours Worked for each Employee(ie. Clock Number)\n" );
/* Loop for inputting and processing wage data */ for( n=0; n < DATA_SETS; ++n ) { associate[n].hours = input_hours_worked ( n, associate[n].id_number ); error_check ( associate[n].hours ); associate[n].overtime = calculate_overtime_hours ( associate[n].hours ); associate[n].gross = calculate_gross_pay ( associate[n].overtime, associate[n].hours, associate[n].wage ); } /* End of for loop */ /* Print out information on employees */ display_wage_data ( associate, DATA_SETS ); } /* End of Main */ (end code)----- Original Message ----- From: "Jackie McBride" <abletec@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx> Sent: Monday, November 05, 2007 3:13 PM Subject: Re: hopefully last C programming question
The problem is your initialization at the beginning of main. I can't fix it cuz I'm completely lost as to what you're doing w/that, but it has to do w/your struct initialization--it's incorrect.
__________View the list's information and change your settings at //www.freelists.org/list/programmingblind