输出显示全 0。总和OT不计算..
#include <stdio.h>
#define STD_HOURS 40.0
#define OT_RATE 1.5
#define SIZE 5
void read_hours(float worked_hours[], long int clockNumber[]);
void calculate_gross(float wage[], float worked_hours[], float gross);
void calculate_gross_ot(float wage[], float worked_hours[]);
void printFunction(long int clockNumber[], float wage[], float worked_hours[], float OT[], float gross);
int i;
int main()
{
long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};/* employee ID */
float gross = 0.0; /* gross */
float OT [SIZE] = {}; /* overtime */
float wage [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35}; /* hourly wage */
float worked_hours [SIZE] = {}; // Hours worked
read_hours(worked_hours, clockNumber);
if (worked_hours[i]>STD_HOURS)
{
calculate_gross_ot(wage, worked_hours);
}
else
{
calculate_gross(wage,worked_hours, gross);
}
printFunction(clockNumber, wage, worked_hours, OT, gross);
return(0);
}
void read_hours(float worked_hours[], long int clockNumber[])
{
for (i=0; i<SIZE; i++)
{
printf("\n Enter Hours for Emlployee ID: %ld\n", clockNumber[i]);
scanf ("%f", &worked_hours[i]);
}
}
void calculate_gross(float wage[], float worked_hours[], float gross)
{
for(i=0; i<SIZE; i++)
gross=(wage[i]*worked_hours[i]);
}
void calculate_gross_ot(float wage[], float worked_hours[])
{
float gross;
float OT[SIZE];
for (i=0; i<SIZE; i++)
{
/* calculating overtime hours */
OT[i]=worked_hours[i]-STD_HOURS;
/* calculating gross pay with overtime */
gross = (STD_HOURS*wage[i]) + (OT[i]*OT_RATE*wage[i]);
//}
}
}
void printFunction(long int clockNumber[], float wage[], float worked_hours[], float OT[], float gross)
{
/* creating a table for the output */
printf("------------------------------------------------\n");
printf("%7s","Clock#");
printf("%7s","Wages");
printf("%7s","Hours");
printf("%7s","OT");
printf("%7s\n","Gross");
printf("------------------------------------------------\n");
for (i=0; i<SIZE; i++)
{
/* printing the results */
printf("%6ld", clockNumber[i]);
printf("%10.2f",wage[i]);
printf("%6.1f", worked_hours[i]);
printf("%6.1f", OT[i]);
printf("%10.2f",gross);
printf("\n");
}
}
该程序用于计算加班时间和不加班时间的总和。输出显示总和 OT 的所有 0。请帮助找出错误在哪里。