Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ok i see that it works now. But why won't it add the hours to end of employee number. Is it ignoring the scanf statement??

Ok i see that it works now. But why won't it add the hours to end of employee number. Is it ignoring the scanf statement??

 
 

#include

/* constants */

#define NUM_EMPL 5

#define OVERTIME_RATE 1.5f

#define STD_WORK_WEEK 40.0f

/* function prototypes */

float getHours(long int clockNumber);

float calcOvertime(float hours);

float calcGrossPay(float hours, float overtimeHrs, float wageRate);

void printHeader(void);

void printEmp(long int clockNumber, float wageRate, float hours, float overtimeHrs, float grossPay);

int main()

{

/* Variable Declarations */

long int clockNumber[NUM_EMPL] = {98401, 526488, 765349, 34645, 127615}; /* ID */

float grossPay[NUM_EMPL]; /* gross pay */

float hours[NUM_EMPL]; /* hours worked in a given week */

int i; /* loop and array index */

float overtimeHrs[NUM_EMPL]; /* overtime hours */

float wageRate[NUM_EMPL] = {10.60, 9.75, 10.50, 12.25, 8.35}; /* hourly wage rate */

/* process each employee */

for (i = 0; i < NUM_EMPL; ++i)

{

/* Read in the hours for an employee */

hours[i] = getHours(clockNumber[i]);

/* calculate overtime hours */

overtimeHrs[i] = calcOvertime(hours[i]);

/* calculate gross pay */

grossPay[i] = calcGrossPay(hours[i], overtimeHrs[i], wageRate[i]);

}

/* print the header info */

printHeader();

/* print out each employee */

for (i = 0; i < NUM_EMPL; ++i)

{

/* Print all the employees - call by reference */

printEmp(clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);

} /* for */

return (0);

}

/* function to get hours worked from user */

float getHours(long int clockNumber)

{

float hoursWorked; /* hours worked in a given week */

/* Read in hours for employee */

printf(" Enter hours worked by emp # %06li: ", clockNumber);

scanf("%f", &hoursWorked);

/* return hours back to the calling function */

return (hoursWorked);

}

/* function to calculate overtime hours */

float calcOvertime(float hours)

{

float overtimeHrs; /* overtime hours worked in a given week */

/* determine overtime hours */

if (hours > STD_WORK_WEEK)

{

overtimeHrs = hours - STD_WORK_WEEK;

}

else

{

overtimeHrs = 0;

}

/* return overtime hours worked */

return overtimeHrs;

}

/* function to calculate gross pay */

float calcGrossPay(float hours, float overtimeHrs, float wageRate)

{

float grossPay; /* gross pay for a given week */

/* calculate gross pay */

if (hours <= STD_WORK_WEEK)

{

grossPay = hours * wageRate;

}

else

{

grossPay = STD_WORK_WEEK * wageRate + overtimeHrs * wageRate * 1.5; }

/* return gross pay */

return grossPay;

}

/* function to print header info */

void printHeader(void)

{

printf(" *** Pay Calculator *** ");

/* print the table header */

printf(" Clock# Wage Hours OT Gross ");

printf("------------------------------------------------ ");

}

void printEmp(long int clockNumber, float wageRate, float hours, float overtimeHrs, float grossPay)

{

printf("%06li %5.2f %5.1f %4.1f %7.2f ", clockNumber, wageRate, hours, overtimeHrs, grossPay);

}

Success #stdin #stdout 0s 5472KB

comments ()

stdin

copy

51.0 42.5 37.5 45.0 0.0

stdout

copy

Enter hours worked by emp # 098401: Enter hours worked by emp # 526488: Enter hours worked by emp # 765349: Enter hours worked by emp # 034645: Enter hours worked by emp # 127615: *** Pay Calculator *** 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.5 0.0 393.75 034645 12.25 45.0 5.0 581.88 127615 8.35 0.0 0.0 0.00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

18. If you have power, then people will dislike and fear you.

Answered: 1 week ago