fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Elissa Huang
  6. //
  7. // Class: C Programming, Spring 2025
  8. //
  9. // Date: February 20, 2025
  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. // Declare variables needed for the program
  29. // Recommend an array for clock, wage, hours,
  30.  
  31. // ... and overtime hours and gross.
  32. // Recommend arrays also for normal pay and overtime pay
  33. // It is OK to pre-fill clock and wage values ... or you can prompt for them
  34.  
  35. // unique employee identifier
  36. long int clockNumber [SIZE] = {98401, 526488, 765349, 34645, 127615};
  37.  
  38. float grossPay [SIZE]; // weekly gross pay - normal pay + overtime pay
  39. float hours [SIZE]; // hours worked in a given week
  40. int i; // loop and array index
  41. float normalPay [SIZE]; // normal weekly pay without any overtime
  42. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  43. float overtimePay [SIZE]; // overtime pay for a given week
  44.  
  45. // hourly pay for each employee
  46. float wageRate [SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  47.  
  48. printf ("\n*** Pay Calculator ***\n\n");
  49.  
  50. // Process each employee one at a time
  51. for (i = 0; i < SIZE; i++)
  52. {
  53.  
  54. // TODO - Prompt and Read in hours worked for employee
  55. printf("Enter hours worked for Clock# %i: \n", clockNumber[i]);
  56. scanf("%f", &hours[i]);
  57.  
  58. // Calculate overtime and gross pay for employee
  59. if (hours[i] >= STD_HOURS)
  60. {
  61. overtimeHrs[i] = hours[i] - STD_HOURS;
  62. // TODO: Calculate arrays normalPay and overtimePay with overtime
  63. normalPay[i] = STD_HOURS * wageRate[i];
  64. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  65.  
  66. }
  67. else // no OT
  68. {
  69. overtimeHrs[i] = 0;
  70. // TODO: Calculate arrays normalPay and overtimePay without overtime
  71. normalPay[i] = hours[i] * wageRate[i];
  72. overtimePay[i] = 0;
  73.  
  74. }
  75.  
  76. // Calculate Gross Pay
  77. grossPay[i] = normalPay[i] + overtimePay[i];
  78. }
  79.  
  80. // TODO: Print a nice table header
  81. printf("\n----------------------------------------------------------------------------------");
  82. printf("\nClock# Wage Hours NormPay OTPay OTHours GrossPay ");
  83.  
  84. // Now that we have all the information in our arrays, we can
  85. // Access each employee and print to screen or file
  86. for (i = 0; i < SIZE; i++)
  87. {
  88. // TODO: Print employee information from your arrays
  89.  
  90. printf("\n%ld %.2f %.1f %.2f %.2f %.2f %.2f ",
  91. clockNumber[i], wageRate[i], hours[i], normalPay[i],
  92. overtimePay[i], overtimeHrs[i], grossPay[i]);
  93. }
  94.  
  95. return(0);
  96. }
Success #stdin #stdout 0s 5288KB
stdin
51.0 42.5 37.0 45.0 0.0
stdout
*** Pay Calculator ***

Enter hours worked for Clock# 98401: 
Enter hours worked for Clock# 526488: 
Enter hours worked for Clock# 765349: 
Enter hours worked for Clock# 34645: 
Enter hours worked for Clock# 127615: 

----------------------------------------------------------------------------------
Clock#   Wage   Hours   NormPay   OTPay   OTHours   GrossPay 
98401   10.60   51.0   424.00   174.90   11.00   598.90   
526488   9.75   42.5   390.00   36.56   2.50   426.56   
765349   10.50   37.0   388.50   0.00   0.00   388.50   
34645   12.25   45.0   490.00   91.88   5.00   581.88   
127615   8.35   0.0   0.00   0.00   0.00   0.00