//*******************************************************
//
// Assignment 3 - Conditionals
//
// Name: Eiddie Katende
//
// Class: C Programming, Fall 2024
// Date: 9/29/24
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
//*******************************************************
#include <stdio.h>
// Declare constants
#define STD_HOURS 40.0
#define NUM_EMPLOYEES 5
#define OVERTIME_RATE 1.5
int main( ) {
int clockNumber; // Employee clock number
float grossPay; // The weekly gross pay including overtime
float hours; // Total hours worked in a week
float overtimeHrs; // Overtime hours worked beyond a normal week (40 hours)
float wageRate; // Hourly wage for an employee
printf ( "\n *** Pay Calculator ***" ) ;
// Process each employee
for ( int i = 0 ; i < NUM_EMPLOYEES; i++ ) {
// Prompt the user for the clock number
printf ( "\n \n Enter clock number: " ) ; scanf ( "%d" , & clockNumber
) ;
// Prompt the user for the wage rate
printf ( "\n Enter wage rate: " ) ;
// Prompt the user for the number of hours worked
printf ( "\n Enter number of hours worked: " ) ;
// Calculate the overtime hours
if ( hours > STD_HOURS) {
overtimeHrs = hours - STD_HOURS;
} else {
overtimeHrs = 0.0 ;
}
// Calculate the gross pay with normal pay and any additional overtime pay
if ( overtimeHrs > 0 ) {
grossPay = ( STD_HOURS * wageRate) + ( overtimeHrs * wageRate * OVERTIME_RATE) ;
} else {
grossPay = hours * wageRate;
}
// Print out information on the current employee
printf ( "\n \n Clock# Wage Hours OT Gross\n " ) ; printf ( "------------------------------------------------\n " ) ; printf ( "%06d %7.2f %7.1f %7.1f %9.2f\n " , clockNumber, wageRate, hours, overtimeHrs, grossPay) ;
}
return 0 ;
}
Ly8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCi8vCi8vIEFzc2lnbm1lbnQgMyAtIENvbmRpdGlvbmFscwovLwovLyBOYW1lOiBFaWRkaWUgS2F0ZW5kZQovLwovLyBDbGFzczogQyBQcm9ncmFtbWluZywgRmFsbCAyMDI0Ci8vIERhdGU6IDkvMjkvMjQKLy8gRGVzY3Jpc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