fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: <Azan Butt>
  6. //
  7. // Class: C Programming, <Spring 2025>
  8. //
  9. // Date: <02-19-25>
  10. //
  11. // Description: Program which determines overtime and
  12. // gross pay for a set of employees with outputs sent
  13. // to standard output (the screen).
  14. //
  15. //********************************************************
  16.  
  17. #include <stdio.h>
  18.  
  19. // constants to use
  20. #define SIZE 5 // number of employees to process
  21. #define STD_HOURS 40.0 // normal work week hours before overtime
  22. #define OT_RATE 1.5 // time and half overtime setting
  23.  
  24. int main()
  25. {
  26.  
  27.  
  28. // unique employee identifier
  29. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615}; // Employees clock number
  30. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35}; // hourly pay for each employee
  31. float hours[SIZE]; // Hours worked in a given week
  32. float normalPay[SIZE]; // Normal weekly pay (no overtime)
  33. float grossPay[SIZE]; // weekly gross pay - normal pay + overtime pay
  34. float overtimeHrs[SIZE]; // Overtime hours worked in a given week
  35. float overtimePay[SIZE]; // Overtime pay for a given week
  36.  
  37.  
  38. int i; // loop and array index
  39.  
  40. printf ("\n*** Pay Calculator ***\n\n");
  41.  
  42. // Process each employee one at a time
  43. for (i = 0; i < SIZE; i++)
  44. {
  45.  
  46. // complete - Prompt and Read in hours worked for employee
  47. printf("Enter hours worked for Employee %ld: ", clockNumber[i]);
  48. scanf("%f", &hours[i]);
  49. // Calculate overtime and gross pay for employee
  50. if (hours[i] > STD_HOURS)
  51. {
  52. overtimeHrs[i] = hours[i] - STD_HOURS;
  53. normalPay[i] = STD_HOURS * wageRate[i];
  54. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  55. // complete: Calculate arrays normalPay and overtimePay with overtime
  56.  
  57.  
  58. }
  59. else // no OT
  60. {
  61. overtimeHrs[i] = 0;
  62. normalPay[i] = hours[i] * wageRate[i];
  63. overtimePay[i] = 0;
  64. // complete: Calculate arrays normalPay and overtimePay without overtime
  65.  
  66. }
  67.  
  68. // Calculate Gross Pay
  69. grossPay[i] = normalPay[i] + overtimePay[i];
  70. }
  71.  
  72. // complete: Print a nice table header
  73. printf("\n-----------------------------------------------------------------------------------------\n");
  74. printf(" Clock# Wage Hours OT Gross\n");
  75. printf("-------------------------------------------------------------------------------------------\n");
  76.  
  77. // Now that we have all the information in our arrays, we can
  78. // Access each employee and print to screen or file
  79. for (i = 0; i < SIZE; i++)
  80. {
  81. // complete: Print employee information from your arrays
  82. printf("%8ld %5.2f %5.1f %5.1f %8.2f\n", clockNumber[i], wageRate[i], hours[i], overtimeHrs[i], grossPay[i]);
  83.  
  84.  
  85. }
  86.  
  87. return(0);
  88. }//main
Success #stdin #stdout 0s 5288KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***

Enter hours worked for Employee 98401: Enter hours worked for Employee 526488: Enter hours worked for Employee 765349: Enter hours worked for Employee 34645: Enter hours worked for Employee 127615: 
-----------------------------------------------------------------------------------------
  Clock#	Wage  Hours	    OT		 Gross
-------------------------------------------------------------------------------------------
   98401   10.60   51.0    11.0     598.90
  526488    9.75   42.5     2.5     426.56
  765349   10.50   37.0     0.0     388.50
   34645   12.25   45.0     5.0     581.88
  127615    8.35    0.0     0.0       0.00