//*******************************************************
//
// Assignment 4 - Arrays
//
// Name: <Tasos Paloukos>
//
// Class: C Programming, <Fall 2024>
//
// Date: <October 3,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 to use
#define SIZE 5 // number of employees to process
#define STD_HOURS 40.0 // normal work week hours before overtime
#define OT_RATE 1.5 // time and half overtime setting
int main( )
{
// Declare variables needed for the program
long int clockNumber[ SIZE] = { 98401 , 526488 , 765349 , 34645 , 127615 } ;
float grossPay[ SIZE] ; // weekly gross pay - normal pay + overtime pay
float hours[ SIZE] ; // hours worked in a given week
int i; // loop and array index
float overtimeHrs[ SIZE] ; // overtime hours worked in a given week
float overtimePay[ SIZE] ; // overtime pay for a given week
float wageRate[ SIZE] = { 10.6 , 9.75 , 10.5 , 12.25 , 8.35 } ;
printf ( "\n *** Pay Calculator ***\n \n " ) ;
// Process each employee one at a time
for ( i = 0 ; i < SIZE; i++ )
{
// Prompt and Read in hours worked for employee
printf ( "Enter hours worked for employee %08ld: " , clockNumber
[ i
] ) ;
// Calculate overtime and gross pay for employee
if ( hours[ i] > STD_HOURS)
{
overtimeHrs[ i] = hours[ i] - STD_HOURS;
overtimePay[ i] = overtimeHrs[ i] * wageRate[ i] * OT_RATE;
}
else // no OT
{
overtimeHrs[ i] = 0 ;
overtimePay[ i] = 0 ;
}
// Calculate Gross Pay
grossPay[ i] = ( hours[ i] - overtimeHrs[ i] ) * wageRate[ i] + overtimePay[ i] ;
}
// Print a nice table header
printf ( "--------------------------------------------------------------------------\n " ) ; printf ( " Clock# Wage Hours OT Gross\n " ) ; printf ( "--------------------------------------------------------------------------\n " ) ;
// Now that we have all the information in our arrays, we can
// Access each employee and print to screen or file
for ( i = 0 ; i < SIZE; i++ )
{
printf ( "%08ld %6.2f %6.1f %6.1f %9.2f\n " , clockNumber
[ i
] , wageRate
[ i
] , hours
[ i
] , overtimeHrs
[ i
] , grossPay
[ i
] ) ; }
return 0 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