Code compiles but doesn't run
Here is my code:
Code:
#include <stdio.h>
/*Structure declaration*/
struct employee
{
long id_number;
float wage;
float hours;
float overtime;
float gross;
};
/*Variable declaration (global)*/
struct employee data[5] = { {98401, 10.60}, {526488, 9.75}, {765349, 10.50},
{34645, 12.25}, {127615, 8.35} };
struct employee get_hours (struct employee data[])
{
int temp, i = temp;
for (temp=1; temp<6; ++temp)
{
printf ("Enter employee #%06d hours worked: ", data[temp-1].id_number);
scanf ("%f", &data[temp-1].hours);
}
return (data[i]);
}
struct employee calculate_overtime (struct employee data[])
{
int temp, i = temp;
for (temp=1; temp<6; ++temp)
{
if (data[temp-1].hours > 40)
data[temp-1].overtime = data[temp-1].hours - 40;
else
data[temp-1].overtime = 0;
}
return (data[i]);
}
struct employee calculate_gross (struct employee data[])
{
int temp, i = temp;
for (temp=1; temp<6; ++temp)
{
if (data[temp-1].overtime > 0)
data[temp-1].gross = (data[temp-1].wage * 40) +
((data[temp-1].wage * 1.5) * data[temp-1].overtime);
else
data[temp-1].gross = (data[temp-1].wage * data[temp-1].hours) +
((data[temp-1].wage * 1.5) * data[temp-1].overtime);
}
return (data[i]);
}
void output (struct employee data[])
{
int temp;
printf ("\n\n");
printf ("--------------------------------------------------------\n");
printf ("Clock # Pay Rate Hours OT Gross Pay\n");
printf ("--------------------------------------------------------\n");
for (temp=1; temp<6; ++temp)
{
printf ("%06d $%5.2f %5.1f %5.1f $%6.2f\n",
data[temp-1].id_number, data[temp-1].wage, data[temp-1].hours,
data[temp-1].overtime, data[temp-1].gross);
}
}
main ()
{
int i;
/*Execute functions*/
for (i=1; i<6; ++i)
{
get_hours (data);
calculate_overtime (data);
calculate_gross (data);
}
output (data);
printf ("\n");
system("PAUSE");
}
This code compiles with no errors, but crashes during the 'output' function. Can anyone assist me in figuring out why this is happening?
BTW: yes, I am a student. :)