fork download
  1. //*******************************************************
  2. //
  3. // Homework: Assignment 4 - Arrays
  4. //
  5. // Name: Jessica Theman
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: October 5, 2025
  10. //
  11. // Description: Program which determines overtime and gross
  12. // pay for a set of employees with outputs sent to standard
  13. // output (the screen) using arrays.
  14. //
  15. //
  16. //********************************************************
  17.  
  18. #include <stdio.h>
  19.  
  20. // Declare constants
  21. #define STD_HOURS 40.0 //Standard hours
  22. #define OVRTM_PAY 1.5 //Overtime pay rate to multiply standard wage by
  23. #define SIZE 5 //Symbolic constant for array size
  24.  
  25. int main( )
  26. {
  27. //Unique employee clock number
  28. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  29.  
  30. float grossPay [SIZE]; //The weekly gross pay which is normalPay + any overtimePay
  31. float hours [SIZE]; //Total hours worked in a week
  32. int i; //Loop and array index
  33. float normalPay [SIZE]; //Standard weekly normal pay without overtime
  34. float overtimeHrs [SIZE]; //Any hours worked past the normal scheduled work week
  35. float overtimePay[SIZE]; //Additional overtime pay for any overtime hours worked
  36.  
  37. //Hourly wage for each employee
  38. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  39.  
  40. printf("\n ***** PAY CALCULATOR ***** \n");
  41.  
  42. // Process each employee one at a time
  43. for (i = 0; i < SIZE; i++)
  44. {
  45. //Prompt and Read in hours worked for employee
  46. printf("\nEnter hours worked for employee %ld: \n", clockNumber[i]);
  47. scanf("%f", &hours[i]);
  48.  
  49. // Calculate overtime and gross pay for employee
  50. if (hours[i] >= STD_HOURS)
  51. {
  52. overtimeHrs[i] = hours[i] - STD_HOURS;
  53. //Calculate arrays normalPay and overtimePay with overtime
  54. normalPay[i] = STD_HOURS * wageRate[i];
  55. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OVRTM_PAY;
  56. }
  57. else //No overtime
  58. {
  59. overtimeHrs[i] = 0;
  60. //Calculate arrays normalPay and overtimePay without overtime
  61. normalPay[i] = hours[i] * wageRate[i];
  62. overtimePay[i] = 0.0;
  63. }
  64.  
  65. // Calculate Gross Pay
  66. grossPay[i] = normalPay[i] + overtimePay[i];
  67. }
  68.  
  69. //Table Header
  70. printf("\n ***** PAYROLL SUMMARY ***** ");
  71. printf("\n-------------------------------------------------\n");
  72. printf("Clock# Wage Hours OT Hrs Gross Pay");
  73. printf("\n-------------------------------------------------\n");
  74.  
  75. // Access each employee and print to screen or file
  76. for (i = 0; i < SIZE; i++)
  77. {
  78. //Print employee information from your arrays
  79. printf("\n%-9li $%-8.2f %-9.1f %-9.1f $%-7.2f",
  80. clockNumber[i],
  81. wageRate[i],
  82. hours[i],
  83. overtimeHrs[i],
  84. grossPay[i]
  85. );
  86. }
  87. printf("\n-------------------------------------------------\n");
  88.  
  89. return(0);
  90. }
Success #stdin #stdout 0.01s 5296KB
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: 

			***** PAYROLL SUMMARY *****			
-------------------------------------------------
Clock#    Wage     Hours    OT Hrs		Gross Pay
-------------------------------------------------

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