0

出力はすべて 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 時間の有無にかかわらず総計を計算するために使用されます。出力では、グロスと OT がすべて 0 になっています。どこが間違っているのかを理解するのを手伝ってください。

4

2 に答える 2

0

から関数に渡しOTます。calculate_gross_ot()main()

 ...
 calculate_gross_ot(wage, worked_hours, OT);
 ...


 void calculate_gross_ot(float wage[], float worked_hours[], float OT[])
于 2013-10-13T18:45:47.407 に答える