2013-10-13 1 views
0

출력이 모두 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"); 

} 


    } 

이 프로그램은 구약 시간을 포함하거나 포함하지 않는 총계를 계산하는 데 사용됩니다. 출력은 총액과 구약에 대해 모두 0을 표시합니다. 실수가 어디인지 알아내는 데 도움이됩니다.

+0

무엇을 시도 했습니까? StackOverflow는 실수를 수정하는 것이 아니라 문제를 해결할 수 있도록 설계되었습니다. – FeifanZ

답변

3

첫 번째 경우에는 gross을 값으로 전달합니다.

두 번째 경우에는 전혀 전달하지 않습니다 (이 함수에는 gross이라는 로컬 함수가 있음).

두 경우 모두 해당 기능이 gross으로 변경 될 때마다이 변경 사항이 호출자에게 전파되지 않습니다.

gross을 포인터로 전달하거나 return 문을 사용하여 함수에서 값을 반환하고 반환 유형을 적절하게 변경해야합니다.

0

OTcalculate_gross_ot() 함수에 main()에서 전달하십시오.

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


void calculate_gross_ot(float wage[], float worked_hours[], float OT[]) 
관련 문제