//*******************************************************
//
// 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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