//*******************************************************
//
// Assignment 4 - Arrays
//
// Name: Thomas Scappaticci
//
// Class: C Programming, Spring 2024
//
// Date: 2/18/2024
//
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
//********************************************************
#include <stdio.h>
// Constants
#define SIZE 5 // Number of Employees to process
#define STD_HOURS 40.0 // Standard Work Hours per week
#define OT_PAY 1.5 // ADDED: Pay rate for OT
int main ()
{
long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615}; // Array for Employee ID
float grossPay [SIZE]; // weekly gross pay which is normalPay + overtimePay
float hours [SIZE]; // number of hours worked per week
float normalPay [SIZE]; // Standard pay per week without overtime
float overtimeHrs [SIZE]; // number of hours worked per week
float overtimePay [SIZE]; // additional pay for overtime hours worked
int i; // Loop and Array INDEX
float TotalwageRate; // Sum of all wage rates
float Totalhours; // Sum of all hours worked
float TotalovertimeHrs; // Sum of all overtime hours worked
float TotalgrossPay; // Sum of all gross payment
float AVGwageRate; // Average of all wage rates
float AVGhours; // Average of all hours worked
float AVGovertimeHrs; // Average of all overtime hours worked
float AVGgrossPay; // Average of all gross payment
float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35}; // Hourly Wage per Employee
// Header Print
printf ("\n\t*** Pay Calculator ***\n");
// Process each employee's hours worked and calculate pay and overtime
for (int i = 0; i < SIZE; i++ )
{
// Prompt the user for the number of hours worked
printf ("\nEnter the number of hours worked for Employee %d: \n", clockNumber[i]);
scanf ("%f", &hours[i]);
// calculate overtime hours, normal pay, and overtime pay
// *IF* Statement if hours exceed standard hours
if (hours[i] > STD_HOURS)
{
overtimeHrs[i] = hours[i] - STD_HOURS; // Overtime = Dif between hours worked and standard hours
normalPay[i] = wageRate[i] * STD_HOURS; // Normal pay = Wages * std hours
overtimePay[i] = (wageRate[i] * OT_PAY) * overtimeHrs[i]; // overtime = wages * OT_PAY * overtime hours
} //if
// *ELSE* Statement if hours do not exceed standard hours
else{
overtimeHrs[i] = 0; // No overtime worked
normalPay[i] = wageRate[i] * hours[i]; // Normal pay = Wages * std hours
overtimePay[i] = 0; // No overtime pay
} // else
// calculate gross pay with normal and overtime pay
grossPay[i] = normalPay[i] + overtimePay[i];
} // for
// Header for Employee Info Table
printf ("\n\n\t----------------------------------------------------------\n");
printf ("\t\t\tClock # Wage Hours OT Gross\n");
printf ("\t----------------------------------------------------------\n");
// Print array info for each employee
for (int i = 0; i < SIZE; i++ )
{
printf("\t\t\t%06d %5.2f %5.1f %5.1f %8.2f\n",
clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
} // for
// Calculate Total and Average Values
for (int i = 0; i < SIZE; i++ )
{
TotalwageRate = TotalwageRate + wageRate[i];
Totalhours = Totalhours + hours[i];
TotalovertimeHrs = TotalovertimeHrs + overtimeHrs[i];
TotalgrossPay = TotalgrossPay + grossPay[i];
AVGwageRate = TotalwageRate / SIZE;
AVGhours = Totalhours / SIZE;
AVGovertimeHrs = TotalovertimeHrs / SIZE;
AVGgrossPay = TotalgrossPay / SIZE;
}
// Print out Total Values and Average Values
printf ("\n\n\t----------------------------------------------------------\n");
printf ("\tTotal");
printf("\t\t%5.2f %5.1f %5.1f %8.2f\n",
TotalwageRate, Totalhours, TotalovertimeHrs, TotalgrossPay);
printf ("\tAverage");
printf("\t\t%5.2f %5.1f %5.1f %8.2f\n",
AVGwageRate, AVGhours, AVGovertimeHrs, AVGgrossPay);
// Bottom Print
printf("\n\n\tThank you for using employee calculator!");
return (0); // success
} // main