fork download
  1. //********************************************************
  2. //
  3. // Assignment 7 - Structures and Strings
  4. //
  5. // Name: <Mike Jason>
  6. //
  7. // Class: C Programming, <Spring 2026>
  8. //
  9. // Date: <03/29/2026>
  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. // This assignment also adds the employee name, their tax state,
  16. // and calculates the state tax, federal tax, and net pay. It
  17. // also calculates totals, averages, minimum, and maximum values.
  18. //
  19. // Call by Reference design
  20. //
  21. //********************************************************
  22.  
  23. // necessary header files
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <ctype.h>
  27.  
  28. // define constants
  29. #define SIZE 5 // number of employees
  30. #define STD_HOURS 40.0 // standard hours before overtime kicks in
  31. #define OT_RATE 1.5 // overtime pay multiplier
  32. #define MA_TAX_RATE 0.05 // Massachusetts state tax rate
  33. #define NH_TAX_RATE 0.0 // New Hampshire state tax rate (no income tax)
  34. #define VT_TAX_RATE 0.06 // Vermont state tax rate
  35. #define CA_TAX_RATE 0.07 // California state tax rate
  36. #define DEFAULT_TAX_RATE 0.08 // default tax rate for any other state
  37. #define NAME_SIZE 20 // max size for a full name string
  38. #define TAX_STATE_SIZE 3 // max size for a 2-letter state + null terminator
  39. #define FED_TAX_RATE 0.25 // federal tax rate applied to all employees
  40. #define FIRST_NAME_SIZE 10 // max size for the first name string
  41. #define LAST_NAME_SIZE 10 // max size for the last name string
  42.  
  43. // Define a structure type to store an employee name.
  44. // Breaking the name into first and last gives flexibility for
  45. // formatting and future extensions (middle name, prefix, etc.).
  46. struct name
  47. {
  48. char firstName[FIRST_NAME_SIZE]; // employee's first name
  49. char lastName [LAST_NAME_SIZE]; // employee's last name
  50. };
  51.  
  52. // Define a structure type to pass employee data between functions.
  53. // Note that the structure type is global, but variables of this type
  54. // should be declared locally in functions and passed as needed.
  55. struct employee
  56. {
  57. struct name empName; // employee's first and last name
  58. char taxState[TAX_STATE_SIZE]; // 2-letter state abbreviation where work is performed
  59. long int clockNumber; // unique employee clock/ID number
  60. float wageRate; // hourly wage rate
  61. float hours; // total hours worked in the week
  62. float overtimeHrs; // overtime hours worked beyond STD_HOURS
  63. float grossPay; // gross pay before taxes
  64. float stateTax; // state tax owed based on tax state
  65. float fedTax; // federal tax owed
  66. float netPay; // take-home pay after all taxes
  67. };
  68.  
  69. // This structure type defines the running totals of all floating point
  70. // items so they can be summed and used to calculate averages.
  71. struct totals
  72. {
  73. float total_wageRate; // sum of all employee wage rates
  74. float total_hours; // sum of all hours worked
  75. float total_overtimeHrs; // sum of all overtime hours
  76. float total_grossPay; // sum of all gross pay values
  77. float total_stateTax; // sum of all state taxes
  78. float total_fedTax; // sum of all federal taxes
  79. float total_netPay; // sum of all net pay values
  80. };
  81.  
  82. // This structure type defines the minimum and maximum values of all
  83. // floating point items so they can be displayed in the final report.
  84. struct min_max
  85. {
  86. float min_wageRate; // minimum wage rate across all employees
  87. float min_hours; // minimum hours worked
  88. float min_overtimeHrs; // minimum overtime hours
  89. float min_grossPay; // minimum gross pay
  90. float min_stateTax; // minimum state tax
  91. float min_fedTax; // minimum federal tax
  92. float min_netPay; // minimum net pay
  93. float max_wageRate; // maximum wage rate across all employees
  94. float max_hours; // maximum hours worked
  95. float max_overtimeHrs; // maximum overtime hours
  96. float max_grossPay; // maximum gross pay
  97. float max_stateTax; // maximum state tax
  98. float max_fedTax; // maximum federal tax
  99. float max_netPay; // maximum net pay
  100. };
  101.  
  102. // Function prototypes - declared here so functions can be called
  103. // before their full definitions appear below main
  104. void getHours (struct employee employeeData[], int theSize);
  105. void calcOvertimeHrs (struct employee employeeData[], int theSize);
  106. void calcGrossPay (struct employee employeeData[], int theSize);
  107. void printHeader (void);
  108. void printEmp (struct employee employeeData[], int theSize);
  109. void calcStateTax (struct employee employeeData[], int theSize);
  110. void calcFedTax (struct employee employeeData[], int theSize);
  111. void calcNetPay (struct employee employeeData[], int theSize);
  112. struct totals calcEmployeeTotals (struct employee employeeData[],
  113. struct totals employeeTotals,
  114. int theSize);
  115. struct min_max calcEmployeeMinMax (struct employee employeeData[],
  116. struct min_max employeeMinMax,
  117. int theSize);
  118. void printEmpStatistics (struct totals employeeTotals,
  119. struct min_max employeeMinMax,
  120. int theSize);
  121.  
  122. int main ()
  123. {
  124.  
  125. // Set up a local array of employee structures with pre-initialized
  126. // name, tax state, clock number, and wage rate for each employee.
  127. // Hours and calculated fields will be filled in later.
  128. struct employee employeeData[SIZE] = {
  129. { {"Connie", "Cobol"}, "MA", 98401, 10.60 },
  130. { {"Mary", "Apl"}, "NH", 526488, 9.75 },
  131. { {"Frank", "Fortran"}, "VT", 765349, 10.50 },
  132. { {"Jeff", "Ada"}, "NY", 34645, 12.25 },
  133. { {"Anton", "Pascal"}, "CA", 127615, 8.35 }
  134. };
  135.  
  136. // Structure to accumulate running totals of all float fields;
  137. // initialized to zero so the running sums start clean.
  138. struct totals employeeTotals = {0, 0, 0, 0, 0, 0, 0};
  139.  
  140. // Structure to hold minimum and maximum values of all float fields;
  141. // initialized to zero and will be set to real values in calcEmployeeMinMax.
  142. struct min_max employeeMinMax = {0, 0, 0, 0, 0, 0, 0,
  143. 0, 0, 0, 0, 0, 0, 0};
  144.  
  145. // Prompt the user to enter hours worked for each employee
  146. getHours (employeeData, SIZE);
  147.  
  148. // Calculate the overtime hours for each employee
  149. calcOvertimeHrs (employeeData, SIZE);
  150.  
  151. // Calculate the weekly gross pay for each employee
  152. calcGrossPay (employeeData, SIZE);
  153.  
  154. // Calculate the state tax owed for each employee
  155. calcStateTax (employeeData, SIZE);
  156.  
  157. // Calculate the federal tax owed for each employee
  158. calcFedTax (employeeData, SIZE);
  159.  
  160. // Calculate the net take-home pay for each employee
  161. calcNetPay (employeeData, SIZE);
  162.  
  163. // Accumulate totals across all employees (Call by Value - returns updated struct)
  164. employeeTotals = calcEmployeeTotals (employeeData, employeeTotals, SIZE);
  165.  
  166. // Determine minimum and maximum values across all employees (Call by Value)
  167. employeeMinMax = calcEmployeeMinMax (employeeData, employeeMinMax, SIZE);
  168.  
  169. // Print the table column headers
  170. printHeader();
  171.  
  172. // Print the details for each employee in a formatted table row
  173. printEmp (employeeData, SIZE);
  174.  
  175. // Print the summary statistics: totals, averages, min, and max
  176. printEmpStatistics (employeeTotals, employeeMinMax, SIZE);
  177.  
  178. return (0); // success
  179.  
  180. } // main
  181.  
  182. //**************************************************************
  183. // Function: getHours
  184. //
  185. // Purpose: Prompts the user to enter the number of hours worked
  186. // for each employee and stores the value in the
  187. // employee array of structures.
  188. //
  189. // Parameters:
  190. //
  191. // employeeData - array of employee structures (passed by reference)
  192. // theSize - the number of employees in the array
  193. //
  194. // Returns: void
  195. //
  196. //**************************************************************
  197.  
  198. void getHours (struct employee employeeData[], int theSize)
  199. {
  200. int i; // loop index used to iterate through each employee
  201.  
  202. // Loop through each employee and read in their hours worked
  203. for (i = 0; i < theSize; ++i)
  204. {
  205. // Prompt using the employee's clock number for clarity
  206. printf ("\nEnter hours worked by emp # %06li: ", employeeData[i].clockNumber);
  207.  
  208. // Read the hours directly into the structure member (by reference via array)
  209. scanf ("%f", &employeeData[i].hours);
  210. }
  211.  
  212. } // getHours
  213.  
  214. //**************************************************************
  215. // Function: printHeader
  216. //
  217. // Purpose: Prints the column header rows for the employee
  218. // pay report table.
  219. //
  220. // Parameters: none
  221. //
  222. // Returns: void
  223. //
  224. //**************************************************************
  225.  
  226. void printHeader (void)
  227. {
  228. printf ("\n\n*** Pay Calculator ***\n");
  229.  
  230. // Print the top separator line
  231. printf ("\n--------------------------------------------------------------");
  232. printf ("-------------------");
  233.  
  234. // Print the two header rows with column labels
  235. printf ("\nName Tax Clock# Wage Hours OT Gross ");
  236. printf (" State Fed Net");
  237. printf ("\n State Pay ");
  238. printf (" Tax Tax Pay");
  239.  
  240. // Print the bottom separator line under the header
  241. printf ("\n--------------------------------------------------------------");
  242. printf ("-------------------");
  243.  
  244. } // printHeader
  245.  
  246. //*************************************************************
  247. // Function: printEmp
  248. //
  249. // Purpose: Iterates through the employee array and prints all
  250. // computed fields for each employee in a formatted
  251. // table row.
  252. //
  253. // Parameters:
  254. //
  255. // employeeData - array of employee structures (passed by reference)
  256. // theSize - the number of employees in the array
  257. //
  258. // Returns: void
  259. //
  260. //**************************************************************
  261.  
  262. void printEmp (struct employee employeeData[], int theSize)
  263. {
  264. int i; // loop index used to iterate through each employee
  265.  
  266. // Character array to hold the combined "First Last" full name.
  267. // Size accounts for both name parts plus one space and the null terminator.
  268. char name[FIRST_NAME_SIZE + LAST_NAME_SIZE + 1];
  269.  
  270. // Loop through each employee and print a formatted row
  271. for (i = 0; i < theSize; ++i)
  272. {
  273. // Build the full name string by copying the first name,
  274. // appending a space, then appending the last name.
  275. // Using C string functions here demonstrates how to work with
  276. // string data stored in separate structure members.
  277. strcpy (name, employeeData[i].empName.firstName);
  278. strcat (name, " "); // insert a space between first and last name
  279. strcat (name, employeeData[i].empName.lastName);
  280.  
  281. // Print all fields for this employee in one formatted line
  282. printf ("\n%-20.20s %-2.2s %06li %5.2f %4.1f %4.1f %7.2f %6.2f %7.2f %8.2f",
  283. name,
  284. employeeData[i].taxState,
  285. employeeData[i].clockNumber,
  286. employeeData[i].wageRate,
  287. employeeData[i].hours,
  288. employeeData[i].overtimeHrs,
  289. employeeData[i].grossPay,
  290. employeeData[i].stateTax,
  291. employeeData[i].fedTax,
  292. employeeData[i].netPay);
  293.  
  294. } // for
  295.  
  296. } // printEmp
  297.  
  298. //*************************************************************
  299. // Function: printEmpStatistics
  300. //
  301. // Purpose: Prints the summary section of the report, including
  302. // the totals, averages, minimums, and maximums for all
  303. // floating point fields across all employees.
  304. //
  305. // Parameters:
  306. //
  307. // employeeTotals - structure holding the running sum of all
  308. // employee floating point fields
  309. // employeeMinMax - structure holding the minimum and maximum
  310. // values for all employee floating point fields
  311. // theSize - total number of employees processed; used
  312. // to guard against divide-by-zero when averaging
  313. //
  314. // Returns: void
  315. //
  316. //**************************************************************
  317.  
  318. void printEmpStatistics (struct totals employeeTotals,
  319. struct min_max employeeMinMax,
  320. int theSize)
  321. {
  322. // Print the separator line before the statistics section
  323. printf ("\n--------------------------------------------------------------");
  324. printf ("-------------------");
  325.  
  326. // Print the totals row for every floating point column
  327. printf ("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  328. employeeTotals.total_wageRate,
  329. employeeTotals.total_hours,
  330. employeeTotals.total_overtimeHrs,
  331. employeeTotals.total_grossPay,
  332. employeeTotals.total_stateTax,
  333. employeeTotals.total_fedTax,
  334. employeeTotals.total_netPay);
  335.  
  336. // Guard against dividing by zero or a negative count
  337. if (theSize > 0)
  338. {
  339. // Print the averages row by dividing each total by the employee count
  340. printf ("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  341. employeeTotals.total_wageRate / theSize,
  342. employeeTotals.total_hours / theSize,
  343. employeeTotals.total_overtimeHrs / theSize,
  344. employeeTotals.total_grossPay / theSize,
  345. employeeTotals.total_stateTax / theSize,
  346. employeeTotals.total_fedTax / theSize,
  347. employeeTotals.total_netPay / theSize);
  348. } // if
  349.  
  350. // Print the minimum values row for every floating point column
  351. printf ("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  352. employeeMinMax.min_wageRate,
  353. employeeMinMax.min_hours,
  354. employeeMinMax.min_overtimeHrs,
  355. employeeMinMax.min_grossPay,
  356. employeeMinMax.min_stateTax,
  357. employeeMinMax.min_fedTax,
  358. employeeMinMax.min_netPay);
  359.  
  360. // Print the maximum values row for every floating point column
  361. printf ("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  362. employeeMinMax.max_wageRate,
  363. employeeMinMax.max_hours,
  364. employeeMinMax.max_overtimeHrs,
  365. employeeMinMax.max_grossPay,
  366. employeeMinMax.max_stateTax,
  367. employeeMinMax.max_fedTax,
  368. employeeMinMax.max_netPay);
  369.  
  370. } // printEmpStatistics
  371.  
  372. //*************************************************************
  373. // Function: calcOvertimeHrs
  374. //
  375. // Purpose: Calculates the number of overtime hours worked by
  376. // each employee. Any hours beyond STD_HOURS (40) are
  377. // counted as overtime; otherwise overtime is zero.
  378. //
  379. // Parameters:
  380. //
  381. // employeeData - array of employee structures (passed by reference)
  382. // theSize - the number of employees in the array
  383. //
  384. // Returns: void
  385. //
  386. //**************************************************************
  387.  
  388. void calcOvertimeHrs (struct employee employeeData[], int theSize)
  389. {
  390. int i; // loop index used to iterate through each employee
  391.  
  392. // Determine overtime hours for each employee
  393. for (i = 0; i < theSize; ++i)
  394. {
  395. // If the employee worked more than standard hours, the excess is overtime
  396. if (employeeData[i].hours >= STD_HOURS)
  397. {
  398. employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS;
  399. }
  400. else
  401. {
  402. // No overtime hours earned this week
  403. employeeData[i].overtimeHrs = 0;
  404. }
  405.  
  406. } // for
  407.  
  408. } // calcOvertimeHrs
  409.  
  410. //*************************************************************
  411. // Function: calcGrossPay
  412. //
  413. // Purpose: Calculates the gross pay for each employee by
  414. // combining normal (straight-time) pay with any
  415. // overtime pay earned during the week.
  416. //
  417. // Parameters:
  418. //
  419. // employeeData - array of employee structures (passed by reference)
  420. // theSize - the number of employees in the array
  421. //
  422. // Returns: void
  423. //
  424. //**************************************************************
  425.  
  426. void calcGrossPay (struct employee employeeData[], int theSize)
  427. {
  428. int i; // loop index used to iterate through each employee
  429. float theNormalPay; // pay earned for the standard (non-overtime) hours
  430. float theOvertimePay; // additional pay earned for overtime hours at OT_RATE
  431.  
  432. // Calculate gross pay for each employee
  433. for (i = 0; i < theSize; ++i)
  434. {
  435. // Normal pay covers all hours that are not overtime hours
  436. theNormalPay = employeeData[i].wageRate *
  437. (employeeData[i].hours - employeeData[i].overtimeHrs);
  438.  
  439. // Overtime pay is at 1.5x the regular wage rate
  440. theOvertimePay = employeeData[i].overtimeHrs *
  441. (OT_RATE * employeeData[i].wageRate);
  442.  
  443. // Gross pay is the sum of normal pay and any overtime pay
  444. employeeData[i].grossPay = theNormalPay + theOvertimePay;
  445.  
  446. } // for
  447.  
  448. } // calcGrossPay
  449.  
  450. //*************************************************************
  451. // Function: calcStateTax
  452. //
  453. // Purpose: Calculates the state income tax owed by each employee
  454. // based on the state where they perform their work.
  455. // Tax rates vary by state; any unrecognized state uses
  456. // the default tax rate.
  457. //
  458. // Parameters:
  459. //
  460. // employeeData - array of employee structures (passed by reference)
  461. // theSize - the number of employees in the array
  462. //
  463. // Returns: void
  464. //
  465. //**************************************************************
  466.  
  467. void calcStateTax (struct employee employeeData[], int theSize)
  468. {
  469. int i; // loop index used to iterate through each employee
  470.  
  471. // Determine and apply the appropriate state tax rate for each employee
  472. for (i = 0; i < theSize; ++i)
  473. {
  474. // Normalize the tax state abbreviation to uppercase so that
  475. // comparisons work correctly regardless of input case
  476. if (islower (employeeData[i].taxState[0]))
  477. employeeData[i].taxState[0] = toupper (employeeData[i].taxState[0]);
  478. if (islower (employeeData[i].taxState[1]))
  479. employeeData[i].taxState[1] = toupper (employeeData[i].taxState[1]);
  480.  
  481. // Apply the correct state tax rate based on the employee's work state
  482. if (strcmp (employeeData[i].taxState, "MA") == 0)
  483. // Massachusetts: 5% state income tax
  484. employeeData[i].stateTax = employeeData[i].grossPay * MA_TAX_RATE;
  485. else if (strcmp (employeeData[i].taxState, "NH") == 0)
  486. // New Hampshire: no state income tax (0%)
  487. employeeData[i].stateTax = employeeData[i].grossPay * NH_TAX_RATE;
  488. else if (strcmp (employeeData[i].taxState, "VT") == 0)
  489. // Vermont: 6% state income tax
  490. employeeData[i].stateTax = employeeData[i].grossPay * VT_TAX_RATE;
  491. else if (strcmp (employeeData[i].taxState, "CA") == 0)
  492. // California: 7% state income tax
  493. employeeData[i].stateTax = employeeData[i].grossPay * CA_TAX_RATE;
  494. else
  495. // Any other state uses the default tax rate of 8%
  496. employeeData[i].stateTax = employeeData[i].grossPay * DEFAULT_TAX_RATE;
  497.  
  498. } // for
  499.  
  500. } // calcStateTax
  501.  
  502. //*************************************************************
  503. // Function: calcFedTax
  504. //
  505. // Purpose: Calculates the federal income tax owed by each
  506. // employee. The same flat federal tax rate applies
  507. // to all employees regardless of their state.
  508. //
  509. // Parameters:
  510. //
  511. // employeeData - array of employee structures (passed by reference)
  512. // theSize - the number of employees in the array
  513. //
  514. // Returns: void
  515. //
  516. //**************************************************************
  517.  
  518. void calcFedTax (struct employee employeeData[], int theSize)
  519. {
  520. int i; // loop index used to iterate through each employee
  521.  
  522. // Apply the flat federal tax rate to each employee's gross pay
  523. for (i = 0; i < theSize; ++i)
  524. {
  525. // Federal tax is a flat 25% of gross pay for all employees
  526. employeeData[i].fedTax = employeeData[i].grossPay * FED_TAX_RATE;
  527.  
  528. } // for
  529.  
  530. } // calcFedTax
  531.  
  532. //*************************************************************
  533. // Function: calcNetPay
  534. //
  535. // Purpose: Calculates the net (take-home) pay for each employee
  536. // by subtracting both state and federal taxes from
  537. // the employee's gross pay.
  538. //
  539. // Parameters:
  540. //
  541. // employeeData - array of employee structures (passed by reference)
  542. // theSize - the number of employees in the array
  543. //
  544. // Returns: void
  545. //
  546. //**************************************************************
  547.  
  548. void calcNetPay (struct employee employeeData[], int theSize)
  549. {
  550. int i; // loop index used to iterate through each employee
  551. float theTotalTaxes; // combined total of state and federal taxes owed
  552.  
  553. // Calculate net (take-home) pay for each employee
  554. for (i = 0; i < theSize; ++i)
  555. {
  556. // Combine state and federal taxes into a single tax amount
  557. theTotalTaxes = employeeData[i].stateTax + employeeData[i].fedTax;
  558.  
  559. // Net pay is what the employee actually takes home after all taxes
  560. employeeData[i].netPay = employeeData[i].grossPay - theTotalTaxes;
  561.  
  562. } // for
  563.  
  564. } // calcNetPay
  565.  
  566. //*************************************************************
  567. // Function: calcEmployeeTotals
  568. //
  569. // Purpose: Accumulates a running sum of each floating point
  570. // field across all employees in the array. The updated
  571. // totals structure is returned to the caller.
  572. //
  573. // Parameters:
  574. //
  575. // employeeData - array of employee structures (passed by reference)
  576. // employeeTotals - structure holding running totals (passed by value)
  577. // theSize - the number of employees in the array
  578. //
  579. // Returns: employeeTotals - the updated totals structure
  580. //
  581. //**************************************************************
  582.  
  583. struct totals calcEmployeeTotals (struct employee employeeData[],
  584. struct totals employeeTotals,
  585. int theSize)
  586. {
  587. int i; // loop index used to iterate through each employee
  588.  
  589. // Add each employee's floating point values to the running totals
  590. for (i = 0; i < theSize; ++i)
  591. {
  592. employeeTotals.total_wageRate += employeeData[i].wageRate;
  593. employeeTotals.total_hours += employeeData[i].hours;
  594. employeeTotals.total_overtimeHrs += employeeData[i].overtimeHrs;
  595. employeeTotals.total_grossPay += employeeData[i].grossPay;
  596. employeeTotals.total_stateTax += employeeData[i].stateTax;
  597. employeeTotals.total_fedTax += employeeData[i].fedTax;
  598. employeeTotals.total_netPay += employeeData[i].netPay;
  599.  
  600. } // for
  601.  
  602. // Return the updated totals structure back to the calling function
  603. return (employeeTotals);
  604.  
  605. } // calcEmployeeTotals
  606.  
  607. //*************************************************************
  608. // Function: calcEmployeeMinMax
  609. //
  610. // Purpose: Determines the minimum and maximum values for each
  611. // floating point field across all employees. The first
  612. // employee's values seed both the min and max, and then
  613. // each subsequent employee is compared to update them.
  614. //
  615. // Parameters:
  616. //
  617. // employeeData - array of employee structures (passed by reference)
  618. // employeeMinMax - structure holding min/max values (passed by value)
  619. // theSize - the number of employees in the array
  620. //
  621. // Returns: employeeMinMax - the updated min/max structure
  622. //
  623. //**************************************************************
  624.  
  625. struct min_max calcEmployeeMinMax (struct employee employeeData[],
  626. struct min_max employeeMinMax,
  627. int theSize)
  628. {
  629. int i; // loop index; starts at 1 since index 0 seeds the min and max
  630.  
  631. // Seed both min and max with the first employee's values
  632. employeeMinMax.min_wageRate = employeeData[0].wageRate;
  633. employeeMinMax.min_hours = employeeData[0].hours;
  634. employeeMinMax.min_overtimeHrs = employeeData[0].overtimeHrs;
  635. employeeMinMax.min_grossPay = employeeData[0].grossPay;
  636. employeeMinMax.min_stateTax = employeeData[0].stateTax;
  637. employeeMinMax.min_fedTax = employeeData[0].fedTax;
  638. employeeMinMax.min_netPay = employeeData[0].netPay;
  639.  
  640. employeeMinMax.max_wageRate = employeeData[0].wageRate;
  641. employeeMinMax.max_hours = employeeData[0].hours;
  642. employeeMinMax.max_overtimeHrs = employeeData[0].overtimeHrs;
  643. employeeMinMax.max_grossPay = employeeData[0].grossPay;
  644. employeeMinMax.max_stateTax = employeeData[0].stateTax;
  645. employeeMinMax.max_fedTax = employeeData[0].fedTax;
  646. employeeMinMax.max_netPay = employeeData[0].netPay;
  647.  
  648. // Compare the remaining employees against the current min and max values
  649. for (i = 1; i < theSize; ++i)
  650. {
  651. // --- Wage Rate ---
  652. if (employeeData[i].wageRate < employeeMinMax.min_wageRate)
  653. employeeMinMax.min_wageRate = employeeData[i].wageRate;
  654. if (employeeData[i].wageRate > employeeMinMax.max_wageRate)
  655. employeeMinMax.max_wageRate = employeeData[i].wageRate;
  656.  
  657. // --- Hours Worked ---
  658. if (employeeData[i].hours < employeeMinMax.min_hours)
  659. employeeMinMax.min_hours = employeeData[i].hours;
  660. if (employeeData[i].hours > employeeMinMax.max_hours)
  661. employeeMinMax.max_hours = employeeData[i].hours;
  662.  
  663. // --- Overtime Hours ---
  664. if (employeeData[i].overtimeHrs < employeeMinMax.min_overtimeHrs)
  665. employeeMinMax.min_overtimeHrs = employeeData[i].overtimeHrs;
  666. if (employeeData[i].overtimeHrs > employeeMinMax.max_overtimeHrs)
  667. employeeMinMax.max_overtimeHrs = employeeData[i].overtimeHrs;
  668.  
  669. // --- Gross Pay ---
  670. if (employeeData[i].grossPay < employeeMinMax.min_grossPay)
  671. employeeMinMax.min_grossPay = employeeData[i].grossPay;
  672. if (employeeData[i].grossPay > employeeMinMax.max_grossPay)
  673. employeeMinMax.max_grossPay = employeeData[i].grossPay;
  674.  
  675. // --- State Tax ---
  676. if (employeeData[i].stateTax < employeeMinMax.min_stateTax)
  677. employeeMinMax.min_stateTax = employeeData[i].stateTax;
  678. if (employeeData[i].stateTax > employeeMinMax.max_stateTax)
  679. employeeMinMax.max_stateTax = employeeData[i].stateTax;
  680.  
  681. // --- Federal Tax ---
  682. if (employeeData[i].fedTax < employeeMinMax.min_fedTax)
  683. employeeMinMax.min_fedTax = employeeData[i].fedTax;
  684. if (employeeData[i].fedTax > employeeMinMax.max_fedTax)
  685. employeeMinMax.max_fedTax = employeeData[i].fedTax;
  686.  
  687. // --- Net Pay ---
  688. if (employeeData[i].netPay < employeeMinMax.min_netPay)
  689. employeeMinMax.min_netPay = employeeData[i].netPay;
  690. if (employeeData[i].netPay > employeeMinMax.max_netPay)
  691. employeeMinMax.max_netPay = employeeData[i].netPay;
  692.  
  693. } // for
  694.  
  695. // Return the fully updated min and max structure to the calling function
  696. return (employeeMinMax);
  697.  
  698. } // calcEmployeeMinMax
Success #stdin #stdout 0s 5292KB
stdin
51.0
42.5
37.0
45.0
40.0
stdout
Enter hours worked by emp # 098401: 
Enter hours worked by emp # 526488: 
Enter hours worked by emp # 765349: 
Enter hours worked by emp # 034645: 
Enter hours worked by emp # 127615: 

*** Pay Calculator ***

---------------------------------------------------------------------------------
Name                Tax  Clock# Wage   Hours  OT   Gross   State  Fed      Net
                   State                           Pay     Tax    Tax      Pay
---------------------------------------------------------------------------------
Connie Cobol         MA  098401 10.60  51.0  11.0  598.90  29.95  149.73   419.23
Mary Apl             NH  526488  9.75  42.5   2.5  426.56   0.00  106.64   319.92
Frank Fortran        VT  765349 10.50  37.0   0.0  388.50  23.31   97.12   268.07
Jeff Ada             NY  034645 12.25  45.0   5.0  581.88  46.55  145.47   389.86
Anton Pascal         CA  127615  8.35  40.0   0.0  334.00  23.38   83.50   227.12
---------------------------------------------------------------------------------
Totals:                         51.45 215.5  18.5 2329.84 123.18  582.46  1624.19
Averages:                       10.29  43.1   3.7  465.97  24.64  116.49   324.84
Minimum:                         8.35  37.0   0.0  334.00   0.00   83.50   227.12
Maximum:                        12.25  51.0  11.0  598.90  46.55  149.73   419.23