- /*-------------------------------------------------------------*/
- /* */
- /* HOMEWORK: Homework #5 */
- /* */
- /* Name: Chris Murphy */
- /* */
- /* Class: C Programming */
- /* */
- /* Date: July 8th, 2010 */
- /* */
- /* Description: Utilize functions to streamline pay calculator */
- /* program. */
- /*-------------------------------------------------------------*/
- #include <stdio.h>
- #define OT_coeff 1.5
- #define slavery 168.0
- #define std_hours 40.0
- int main (void)
- {
- /* PROTOTYPES */
- float calcPay (float hours, float wage);
- float getHoursWorked (int clock);
- float overTime (float hours);
- float overTimeDisplay (float hours);
- void printPay (int clock, float wage, float hours, float OT, float gross);
- /* VARIABLES */
- int clock[] = { 98401, 526488, 765349, 34645, 127615 };
- float gross[5];
- float hours[5];
- int i;
- float OT[5];
- float wage[] = { 10.60, 9.75, 10.50, 12.25, 8.35 };
- for ( i = 0; i < 5; i++ ) // The function will do a simple
- hours[i]= getHoursWorked(clock[i]); // repetitive task, and it will be
- // up to the main program to loop.
- for ( i = 0; i < 5; i++ )
- {
- gross[i] = calcPay(hours[i], wage[i]); /* Gross can calculate OT, but it */
- OT[i] = overTimeDisplay(hours[i]); /* can't display the raw number */
- }
- printf("--------------------------------------------\n");
- printf("Clock# Wage Hours OT Gross \n");
- printf("--------------------------------------------\n");
- for ( i = 0; i < 5; i++ )
- printPay(clock[i], wage[i], hours[i], OT[i], gross[i]);
- return 0;
- }
- /**************************************************************************/
- /* Function getHoursWorked */
- /* */
- /* Purpose: This function is called when the user is asked to */
- /* input the hours of an employee. */
- /* */
- /* Parameters: hours - # of hours the employee worked */
- /* clock - the clock number of the employee */
- /* */
- /* Returns: hours worked for the employee. */
- /**************************************************************************/
- float getHoursWorked (int clock)
- {
- float hours;
- printf("Please enter the hours worked for %i: ", clock);
- scanf("%f", &hours);
- printf("\n");
- return hours;
- }
- /**************************************************************************/
- /* Function calcPay */
- /* */
- /* Purpose: This function is called when the program needs to */
- /* calculate the base pay of the employee, and calls */
- /* the OT function if the hours worked are over 40. */
- /* */
- /* Parameters: hours - # of hours the employee worked */
- /* clock - the clock number of the employee */
- /* */
- /* Returns: gross pay for the employee. */
- /**************************************************************************/
- float calcPay (float hours, float wage)
- {
- float OT;
- float gross;
- if ( hours > slavery || hours < 0 )
- {
- gross = 0;
- }
- else if ( hours - std_hours > 0 )
- {
- OT = overTime(hours);
- gross = wage * ( std_hours + OT );
- }
- else
- gross = wage * hours;
- return gross;
- }
- /**************************************************************************/
- /* Function overTime */
- /* */
- /* Purpose: This function is used if OT calculations are needed. */
- /* */
- /* Parameters: hours - # of hours the employee worked */
- /* OT - the weighted value of the overtime work. */
- /* this is done to make calculations in calcPay easier.*/
- /* */
- /* Returns: overtime worked by the employee. */
- /**************************************************************************/
- float overTime (float hours)
- {
- float OT;
- OT = ( hours - std_hours ) * OT_coeff;
- return OT;
- }
- /**************************************************************************/
- /* Function overTimeDisplay */
- /* */
- /* Purpose: This function is used directly by main to store */
- /* overtime hours. */
- /* */
- /* Parameters: hours - # of hours the employee worked */
- /* OT - the absolute number of overtime hours worked */
- /* for display in main */
- /* */
- /* Returns: overtime to be displayed later. */
- /**************************************************************************/
- float overTimeDisplay (float hours)
- {
- float OT;
- OT = ( hours - std_hours);
- if ( OT < 0 )
- OT = 0;
- return OT;
- }
- /**************************************************************************/
- /* Function printPay */
- /* */
- /* Purpose: This function is used directly by main to display */
- /* the final statistics for the employees. */
- /* */
- /* Parameters: clock - clock # of the employee. */
- /* wage - wages earned by the employee. */
- /* hours - # of hours the employee worked. */
- /* OT - the absolute number of overtime hours worked */
- /* for display in main. */
- /* gross - the gross pay for the employee. */
- /* */
- /* Returns: nothing */
- /**************************************************************************/
- void printPay (int clock, float wage, float hours, float OT, float gross)
- {
- printf("%06i ", clock);
- printf("%5.2f ", wage);
- printf("%5.1f ", hours);
- printf("%5.1f ", OT);
- printf("%5.2f\n", gross);
- }