fork download
  1. //*******************************************************
  2. //
  3. // Assignment 4 - Arrays
  4. //
  5. // Name: Samuel Morris
  6. //
  7. // Class: C Programming, Summer 2025
  8. //
  9. // Date: 07/01/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. /* Define constants */
  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. // employee data
  26. long int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615};
  27. float wageRate[SIZE] = {10.6, 9.75, 10.5, 12.25, 8.35};
  28.  
  29. //
  30. float hours[SIZE]; // hours worked in a given week
  31. float overtimeHrs[SIZE]; // overtime hours worked in a given week
  32. float normalPay[SIZE]; // normal weekly pay without any overtime
  33. float overtimePay[SIZE]; // overtime pay for a given week
  34. float grossPay[SIZE]; // weekly gross pay - normal pay + overtime
  35.  
  36. int i; // loop and array index
  37.  
  38. printf("*** Pay Calculator ***\n\n");
  39.  
  40. // Input and calculation loop
  41. for (i = 0; i < SIZE; i++) {
  42. scanf("%f", &hours[i]); // TODO - Prompt and Read in hours worked for employee
  43.  
  44. // Calculate overtime and gross pay for employee
  45. if (hours[i] >= STD_HOURS) {
  46. overtimeHrs[i] = hours[i] - STD_HOURS;// TODO: Calculate arrays normalPay and overtimePay with
  47. normalPay[i] = STD_HOURS * wageRate[i];
  48. overtimePay[i] = overtimeHrs[i] * wageRate[i] * OT_RATE;
  49. } else {
  50. overtimeHrs[i] = 0.0; // TODO: Calculate arrays normalPay and overtimePay without
  51. normalPay[i] = hours[i] * wageRate[i];
  52. overtimePay[i] = 0.0;
  53. }
  54.  
  55. // Calculate gross pay
  56. grossPay[i] = normalPay[i] + overtimePay[i];
  57. }
  58.  
  59. // Output
  60. // TODO: Print a nice table header
  61. printf("\n--------------------------------------------------------------------------\n");
  62. printf(" Clock# Wage Hours OT Gross\n");
  63. printf("--------------------------------------------------------------------------\n");
  64.  
  65. // Now that we have all the information in our arrays, we can
  66. // Access each employee and print to screen or file
  67.  
  68. for (i = 0; i < SIZE; i++) {
  69. // TODO: Print employee information from your arrays
  70. printf(" %06ld %5.2f %5.1f %6.1f %8.2f\n",
  71. clockNumber[i],
  72. wageRate[i],
  73. hours[i],
  74. overtimeHrs[i],
  75. grossPay[i]);
  76. }
  77.  
  78. return 0;
  79. }
Success #stdin #stdout 0.01s 5320KB
stdin
51.0
42.5
37.0
45.0
0.0
stdout
*** Pay Calculator ***


--------------------------------------------------------------------------
  Clock#   Wage  Hours    OT       Gross
--------------------------------------------------------------------------
 098401   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
 034645   12.25   45.0     5.0     581.88
 127615    8.35    0.0     0.0       0.00