Functions problem. *Need Help*
ok this program has been driving me nutz. I have it working perfectly just useing arrays without functions. But when i go cut n paiste it into functions and try to get it working right it throws up at me. can anyone help mw out? getting lots of really odd errors.
/* The program determines the gross pay and ouputs the following
format:
--------------------------------------------------------------
Clock# Wage Hours OT Gross
--------------------------------------------------------------
098401 10.60 51.0 11.0 598.90
526488 9.75 42.5 2.5 426.56
765349 10.50 37.0 0.0 388.50
034645 12.25 45.0 5.0 581.88
127615 8.35 0.0 0.0 0.00*/
#include <stdio.h>
#define ARRAY_SIZE 5
void Get_Hours(long int[], float[],int);
void Calculate_Gross_Pay(float[], float[], float[], float[], int);
void Calculate_Overtime_Pay();
void Print_Header();
void Print_Results();
/************************************************** ************************/
/* Function Print_Header - */
/* */
/* Purpose: This function will print the header for the output */
/* and send it to the screen. */
/* */
/* Parameters: none */
/* */
/* Returns: void */
/************************************************** ************************/
void Print_Header (void)
{
printf ("--------------------------------------------------------------\n");
printf ("Clock# Wage Hours OT Gross \n");
printf ("--------------------------------------------------------------\n");
}
/************************************************** ************************/
/* Function Print_Results */
/* */
/* Purpose: This function will print the results of our program */
/* to the screen following the Print_header function */
/* */
/* Parameters: */
/* */
/* Returns: void */
/************************************************** ************************/
void Print_Results (long int clock_number[], float wages_array[], float hours_array[], float othours_array[], float gross_array[])
{
int i;
for( i = 0; i < 5; ++i)
{
printf ("%06i %5.2f %5.1f %5.1f %5.2f\n", clock_number[i], wages_array[i], hours_array[i], othours_array[i], gross_array[i]);
}
}
/************************************************** ************************/
/* Function Get_Hours */
/* */
/* Purpose: This function will */
/* */
/* */
/* */
/* Parameters: */
/* */
/* */
/* */
/* Returns: */
/************************************************** ************************/
void Get_Hours (long int clock_number[],
float hours_array[])
{
int i;
for( i = 0; i < 5; ++i)
{
printf ("Enter hours for %i", clock_number[i]);
scanf ("&hours_array[i]);
}
}
/************************************************** ************************/
/* Function Calculate_Gross_Pay */
/* */
/* Purpose: This function will calculate the gross pay for five */
/* employees. It will add to the gross pay any overtime */
/* pay if necessary. */
/* */
/* Parameters: wages_array - array of wage rates for each employee */
/* hours_array - array of # of hours each employee worked */
/* otpay_array - array of overtime pay for each employee */
/* gross_array - an array of the calculated gross pay for */
/* each employee. */
/* emp_count - the number of total employees */
/* */
/* Returns: Nothing since the gross_pay array is passed by reference */
/************************************************** ************************/
void Calculate_Gross_Pay (float wages_array[], float hours_array[], float otpay_array[],
float gross_array[], int emp_count)
{
int i;
for (i = 0; i <= 40)
/* calculate gross pay */
gross_array[i] = 40 * wages_array[i] + otpay_array[i];
else
gross_array[i] = wages_array[i] * hours_array[i];
}
}
/************************************************** ************************/
/* Function Calculate_Overtime_Pay */
/* */
/* Purpose: This function will calculate the gross pay for five */
/* employees. It will add to the gross pay any overtime */
/* pay if necessary. */
/* */
/* Parameters: wage - rate of pay for the employee */
/* hours - # of hours the employee worked */
/* ot_pay - overtime pay for the employee */
/* */
/* Returns: gross pay (including any overtime pay) for the employee */
/************************************************** ************************/
void Calculate_Overtime_Pay ()
{
if (othours_array[i] > 40)
return (othours_array[i] - 40);
else /* no overtime was worked */
return (othours_array[i]=0.0);
}
void main ()
/* Create and fill Clock# Array*/
int clock_number[ARRAY_SIZE];
clock_number[0] =98401;
clock_number[1] =526488;
clock_number[2] =765349;
clock_number[3] =34645;
clock_number[4] =127615;
/*Create and fill Wages Array*/
float wages_array[ARRAY_SIZE];
wages_array[0] =10.6f;
wages_array[1] =9.75;
wages_array[2] =10.5;
wages_array[3] =12.25;
wages_array[4] =8.35f;
Delete this thread please....
All set. Got most of it working. Thanks to all the 30+ people who viewed this thread :)