/* * Sara Sprenkle 10/13/04 * example.c * * Example program: calculates the weekly salary for employees, given * a file of employee ids, payrate, and hours worked * * Step 3: implementing salary function */ #include<stdio.h> /* Constants for overtime: Get paid time and a half for working more than 40 hours */ #define OVERTIME_HOURS 40 #define OVERTIME_RATE 1.5 /* Constants for double overtime: Get paid double for working more than 60 hours */ #define DOUBLE_OVERTIME_HOURS 60 #define DOUBLE_OVERTIME_RATE 2 /* * This function calculates and returns the salary for an employee. */ double calculateSalary( float pay_rate, float hours ) { int overtime_hours; /* don't expect hours to be less than 0, but just in case... */ if( hours < 0 ) { return 0; } /* handles the normal case */ if( hours <= OVERTIME_HOURS ) { return hours * pay_rate; } /* at this point, we know that we must deal with overtime */ if( hours <= DOUBLE_OVERTIME_HOURS ) { overtime_hours = hours - OVERTIME_HOURS; return OVERTIME_RATE * pay_rate * overtime_hours + pay_rate * OVERTIME_HOURS; } /* we're in the case with double overtime */ overtime_hours = hours - OVERTIME_HOURS; return DOUBLE_OVERTIME_RATE * pay_rate * overtime_hours + pay_rate * OVERTIME_HOURS; } int main() { /* open input file */ /* read data from input file (employee_id, pay_rate, hours_worked) */ /* calculate the salary for the employee */ /* print the output for the employee */ /* close the file */ return 0; }