fork download
  1. //********************************************************
  2. // Assignment 8 - Structures and Strings and Pointers
  3. //
  4. // Name: <Joy Akoso>
  5. //
  6. // Class: C Programming, <Fall 2025>
  7. //
  8. // Date: <11/7/2025>
  9. //
  10. // Description: Program which determines overtime and
  11. // gross pay for a set of employees with outputs sent
  12. // to standard output (the screen).
  13. //
  14. // This assignment also adds the employee name, their tax state,
  15. // and calculates the state tax, federal tax, and net pay. It
  16. // also calculates totals, averages, minimum, and maximum values.
  17. //
  18. // Array and Structure references are to be replaced with
  19. // pointer references to speed up the processing of this code.
  20. //
  21. // Call by Reference design (using pointers)
  22. //
  23. //********************************************************
  24.  
  25. // necessary header files
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <ctype.h>
  29.  
  30. // define constants
  31. #define SIZE 5
  32. #define STD_HOURS 40.0
  33. #define OT_RATE 1.5
  34. #define MA_TAX_RATE 0.05
  35. #define NH_TAX_RATE 0.0
  36. #define VT_TAX_RATE 0.06
  37. #define CA_TAX_RATE 0.07
  38. #define DEFAULT_TAX_RATE 0.08
  39. #define NAME_SIZE 20
  40. #define FED_TAX_RATE 0.25
  41. #define FIRST_NAME_SIZE 10
  42. #define LAST_NAME_SIZE 10
  43. #define TAX_STATE_SIZE 3
  44.  
  45. // structure type to store an employee name
  46. struct name
  47. {
  48. char firstName[FIRST_NAME_SIZE];
  49. char lastName[LAST_NAME_SIZE];
  50. };
  51.  
  52. //structure type to pass employee data between functions
  53.  
  54. struct employee
  55. {
  56. struct name empName;
  57. char taxState[TAX_STATE_SIZE];
  58. long int clockNumber;
  59. float wageRate;
  60. float hours;
  61. float overtimeHrs;
  62. float grossPay;
  63. float stateTax;
  64. float fedTax;
  65. float netPay;
  66. };
  67.  
  68. // this structure type defines the totals of all floating point items
  69. // so they can be totaled and used also to calculate averages
  70.  
  71. struct totals
  72. {
  73. float total_wageRate;
  74. float total_hours;
  75. float total_overtimeHrs;
  76. float total_grossPay;
  77. float total_stateTax;
  78. float total_fedTax;
  79. float total_netPay;
  80. };
  81.  
  82. // this structure type defines the min and max values of all floating
  83. // point items so they can be display in our final report
  84.  
  85. struct min_max
  86. {
  87. float min_wageRate;
  88. float min_hours;
  89. float min_overtimeHrs;
  90. float min_grossPay;
  91. float min_stateTax;
  92. float min_fedTax;
  93. float min_netPay;
  94. float max_wageRate;
  95. float max_hours;
  96. float max_overtimeHrs;
  97. float max_grossPay;
  98. float max_stateTax;
  99. float max_fedTax;
  100. float max_netPay;
  101. };
  102.  
  103. // prototypes:
  104. // These prototypes have already been transitioned to pointers
  105.  
  106. void getHours (struct employee * emp_ptr, int theSize);
  107. void printEmp (struct employee * emp_ptr, int theSize);
  108.  
  109. void calcEmployeeTotals (struct employee * emp_ptr,
  110. struct totals * emp_totals_ptr,
  111. int theSize);
  112.  
  113. void calcEmployeeMinMax (struct employee * emp_ptr,
  114. struct min_max * emp_MinMax_ptr,
  115. int theSize);
  116.  
  117. // This prototype does not need to use pointers
  118. void printHeader (void);
  119.  
  120. // Updated prototypes using pointers instead of arrays
  121.  
  122. void calcOvertimeHrs(struct employee *emp_ptr, int theSize);
  123. void calcGrossPay(struct employee *emp_ptr, int theSize);
  124. void calcStateTax(struct employee *emp_ptr, int theSize);
  125. void calcFedTax(struct employee *emp_ptr, int theSize);
  126. void calcNetPay(struct employee *emp_ptr, int theSize);
  127. void printEmpStatistics(struct totals *employeeTotals, struct min_max *employeeMinMax, int theSize);
  128.  
  129. int main ()
  130. {
  131.  
  132. // Set up a local variable to store the employee information
  133. // Initialize the name, tax state, clock number, and wage rate
  134. struct employee employeeData[SIZE] = {
  135. { {"Connie", "Cobol"}, "MA", 98401, 10.60},
  136. { {"Mary", "Apl"}, "NH", 526488, 9.75 },
  137. { {"Frank", "Fortran"}, "VT", 765349, 10.50 },
  138. { {"Jeff", "Ada"}, "NY", 34645, 12.25 },
  139. { {"Anton", "Pascal"},"CA",127615, 8.35 }
  140. };
  141.  
  142. // declare a pointer to the array of employee structures
  143. struct employee * emp_ptr;
  144.  
  145. // set the pointer to point to the array of employees
  146. emp_ptr = employeeData;
  147.  
  148. // set up structure to store totals and initialize all to zero
  149. struct totals employeeTotals = {0,0,0,0,0,0,0};
  150.  
  151. // pointer to the employeeTotals structure
  152. struct totals * emp_totals_ptr = &employeeTotals;
  153.  
  154. // set up structure to store min and max values and initialize all to zero
  155. struct min_max employeeMinMax = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  156.  
  157. // pointer to the employeeMinMax structure
  158. struct min_max * emp_minMax_ptr = &employeeMinMax;
  159.  
  160. // Call functions as needed to read and calculate information
  161.  
  162. // Prompt for the number of hours worked by the employee
  163. getHours (employeeData, SIZE);
  164.  
  165. // Calculate the overtime hours
  166. calcOvertimeHrs (employeeData, SIZE);
  167.  
  168. // Calculate the weekly gross pay
  169. calcGrossPay (employeeData, SIZE);
  170.  
  171. // Calculate the state tax
  172. calcStateTax (employeeData, SIZE);
  173.  
  174. // Calculate the federal tax
  175. calcFedTax (employeeData, SIZE);
  176.  
  177. // Calculate the net pay after taxes
  178. calcNetPay (employeeData, SIZE);
  179.  
  180. // Keep a running sum of the employee totals
  181. // Note the & to specify the address of the employeeTotals
  182. // structure. Needed since pointers work with addresses.
  183. calcEmployeeTotals (employeeData,
  184. &employeeTotals,
  185. SIZE);
  186.  
  187. // Keep a running update of the employee minimum and maximum values
  188. calcEmployeeMinMax (employeeData,
  189. &employeeMinMax,
  190. SIZE);
  191. // Print the column headers
  192. printHeader();
  193.  
  194. // print out final information on each employee
  195. printEmp (employeeData, SIZE);
  196.  
  197. // This call has now been transitioned to use pointers. Just like the two structures
  198. //with calcEmployeeTotals and calcEmployeeMinMax.
  199.  
  200. // print the totals and averages for all float items
  201. printEmpStatistics(&employeeTotals,
  202. &employeeMinMax,
  203. SIZE);
  204.  
  205. return (0); // success
  206.  
  207. } // main
  208.  
  209. //**************************************************************
  210. // Function: getHours
  211. //
  212. // Purpose: Obtains input from user, the number of hours worked
  213. // per employee and updates it in the array of structures
  214. // for each employee.
  215. //
  216. // Parameters:
  217. //
  218. // emp_ptr - pointer to array of employees (i.e., struct employee)
  219. // theSize - the array size (i.e., number of employees)
  220. //
  221. // Returns: void (the employee hours gets updated by reference)
  222. //
  223. //**************************************************************
  224.  
  225. void getHours (struct employee * emp_ptr, int theSize)
  226. {
  227.  
  228. int i; // loop index
  229.  
  230. // read in hours for each employee
  231. for (i = 0; i < theSize; ++i)
  232. {
  233. // Read in hours for employee
  234. printf("\nEnter hours worked by emp # %06li: ", emp_ptr->clockNumber);
  235. scanf ("%f", &emp_ptr->hours);
  236.  
  237. // set pointer to next employee
  238. ++emp_ptr;
  239. }
  240.  
  241. } // getHours
  242.  
  243. //**************************************************************
  244. // Function: printHeader
  245. //
  246. // Purpose: Prints the initial table header information.
  247. //
  248. // Parameters: none
  249. //
  250. // Returns: void
  251. //
  252. //**************************************************************
  253.  
  254. void printHeader (void)
  255. {
  256.  
  257. printf ("\n\n*** Pay Calculator ***\n");
  258.  
  259. // print the table header
  260. printf("\n--------------------------------------------------------------");
  261. printf("-------------------");
  262. printf("\nName Tax Clock# Wage Hours OT Gross ");
  263. printf(" State Fed Net");
  264. printf("\n State Pay ");
  265. printf(" Tax Tax Pay");
  266.  
  267. printf("\n--------------------------------------------------------------");
  268. printf("-------------------");
  269.  
  270. } // printHeader
  271.  
  272. //*************************************************************
  273. // Function: printEmp
  274. //
  275. // Purpose: Prints out all the information for each employee
  276. // in a nice and orderly table format.
  277. //
  278. // Parameters:
  279. //
  280. // emp_ptr - pointer to array of struct employee
  281. // theSize - the array size (i.e., number of employees)
  282. //
  283. // Returns: void
  284. //
  285. //**************************************************************
  286.  
  287. void printEmp (struct employee * emp_ptr, int theSize)
  288. {
  289.  
  290. int i; // array and loop index
  291.  
  292. // Used to format the employee name
  293. char name [FIRST_NAME_SIZE + LAST_NAME_SIZE + 1];
  294.  
  295. // read in hours for each employee
  296. for (i = 0; i < theSize; ++i)
  297. {
  298.  
  299. strcpy (name, emp_ptr->empName.firstName);
  300. strcat (name, " "); // add a space between first and last names
  301. strcat (name, emp_ptr->empName.lastName);
  302.  
  303. // Print out a single employee
  304. printf("\n%-20.20s %-2.2s %06li %5.2f %4.1f %4.1f %7.2f %6.2f %7.2f %8.2f",
  305. name, emp_ptr->taxState, emp_ptr->clockNumber,
  306. emp_ptr->wageRate, emp_ptr->hours,
  307. emp_ptr->overtimeHrs, emp_ptr->grossPay,
  308. emp_ptr->stateTax, emp_ptr->fedTax,
  309. emp_ptr->netPay);
  310.  
  311. // set pointer to next employee
  312. ++emp_ptr;
  313.  
  314. } // for
  315.  
  316. } // printEmp
  317.  
  318. //*************************************************************
  319. // Function: printEmpStatistics
  320. //
  321. // Purpose: Prints out the summary totals and averages of all
  322. // floating point value items for all employees
  323. // that have been processed. It also prints
  324. // out the min and max values.
  325. //
  326. // Parameters:
  327. //
  328. // emp_totals_ptr - pointer to a structure containing a running total
  329. // of all employee floating point items
  330. // emp_MinMax_ptr - pointer to a structure containing all the minimum
  331. // and maximum values of all employee
  332. // floating point items
  333. // theSize - the total number of employees processed, used
  334. // to check for zero or negative divide condition.
  335. //
  336. // Returns: void
  337. //
  338. //**************************************************************
  339.  
  340. void printEmpStatistics (struct totals * emp_totals_ptr,
  341. struct min_max * emp_MinMax_ptr,
  342. int theSize)
  343. {
  344.  
  345. // print a separator line
  346. printf("\n--------------------------------------------------------------");
  347. printf("-------------------");
  348.  
  349. // print the totals for all the floating point fields
  350. printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  351. emp_totals_ptr->total_wageRate,
  352. emp_totals_ptr->total_hours,
  353. emp_totals_ptr->total_overtimeHrs,
  354. emp_totals_ptr->total_grossPay,
  355. emp_totals_ptr->total_stateTax,
  356. emp_totals_ptr->total_fedTax,
  357. emp_totals_ptr->total_netPay);
  358.  
  359. // make sure you don't divide by zero or a negative number
  360. if (theSize > 0)
  361. {
  362. // print the averages for all the floating point fields
  363. printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  364. emp_totals_ptr->total_wageRate / theSize,
  365. emp_totals_ptr->total_hours / theSize,
  366. emp_totals_ptr->total_overtimeHrs / theSize,
  367. emp_totals_ptr->total_grossPay / theSize,
  368. emp_totals_ptr->total_stateTax / theSize,
  369. emp_totals_ptr->total_fedTax / theSize,
  370. emp_totals_ptr->total_netPay / theSize);
  371. } // if
  372.  
  373. // print the min and max values
  374.  
  375. printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  376. emp_MinMax_ptr->min_wageRate,
  377. emp_MinMax_ptr->min_hours,
  378. emp_MinMax_ptr->min_overtimeHrs,
  379. emp_MinMax_ptr->min_grossPay,
  380. emp_MinMax_ptr->min_stateTax,
  381. emp_MinMax_ptr->min_fedTax,
  382. emp_MinMax_ptr->min_netPay);
  383.  
  384. printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  385. emp_MinMax_ptr->max_wageRate,
  386. emp_MinMax_ptr->max_hours,
  387. emp_MinMax_ptr->max_overtimeHrs,
  388. emp_MinMax_ptr->max_grossPay,
  389. emp_MinMax_ptr->max_stateTax,
  390. emp_MinMax_ptr->max_fedTax,
  391. emp_MinMax_ptr->max_netPay);
  392.  
  393. } // printEmpStatistics
  394.  
  395. //*************************************************************
  396. // Function: calcOvertimeHrs
  397. //
  398. // Purpose: Calculates the overtime hours worked by an employee
  399. // in a given week for each employee.
  400. //
  401. // Parameters:
  402. //
  403. // emp_ptr - pointer to the first element of an array of
  404. // employee structures (i.e., struct employee)
  405. // theSize - the array size (i.e., number of employees)
  406. //
  407. // Returns: void (the overtime hours gets updated by reference)
  408. //
  409. //**************************************************************
  410.  
  411. void calcOvertimeHrs (struct employee *emp_ptr, int theSize)
  412. {
  413.  
  414. int i; // array and loop index
  415.  
  416. // calculate overtime hours for each employee
  417. for (i = 0; i < theSize; ++i)
  418. {
  419. // Any overtime ?
  420. if (emp_ptr->hours >= STD_HOURS)
  421. {
  422. emp_ptr->overtimeHrs = emp_ptr->hours - STD_HOURS;
  423. }
  424. else // no overtime
  425. {
  426. emp_ptr->overtimeHrs = 0;
  427. }
  428.  
  429. // move to next employee
  430. emp_ptr++;
  431.  
  432. } // for
  433.  
  434. } // calcOvertimeHrs
  435.  
  436. //*************************************************************
  437. // Function: calcGrossPay
  438. //
  439. // Purpose: Calculates the gross pay based on the the normal pay
  440. // and any overtime pay for a given week for each
  441. // employee.
  442. //
  443. // Parameters:
  444. //
  445. // emp_ptr - pointer to the first element of an array of
  446. // employee structures (i.e., struct employee)
  447. // theSize - the array size (i.e., number of employees)
  448. //
  449. // Returns: void (the gross pay gets updated by reference)
  450. //
  451. //**************************************************************
  452.  
  453. void calcGrossPay (struct employee *emp_ptr, int theSize)
  454. {
  455. int i; // loop and array index
  456. float theNormalPay; // normal pay without any overtime hours
  457. float theOvertimePay; // overtime pay
  458.  
  459. // calculate grossPay for each employee
  460. for (i=0; i < theSize; ++i)
  461. {
  462. // calculate normal pay and any overtime pay
  463. theNormalPay = emp_ptr->wageRate *
  464. (emp_ptr->hours - emp_ptr->overtimeHrs);
  465. theOvertimePay = emp_ptr->overtimeHrs *
  466. (OT_RATE * emp_ptr->wageRate);
  467.  
  468. // calculate gross pay for employee as normalPay + any overtime pay
  469. emp_ptr->grossPay = theNormalPay + theOvertimePay;
  470.  
  471. // move to next employee
  472. emp_ptr++;
  473. }
  474.  
  475. } // calcGrossPay
  476.  
  477. //*************************************************************
  478. // Function: calcStateTax
  479. //
  480. // Purpose: Calculates the State Tax owed based on gross pay
  481. // for each employee. State tax rate is based on the
  482. // the designated tax state based on where the
  483. // employee is actually performing the work. Each
  484. // state decides their tax rate.
  485. //
  486. // Parameters:
  487. //
  488. // emp_ptr - pointer to array of employees (i.e., struct employee)
  489. // theSize - the array size (i.e., number of employees)
  490. //
  491. // Returns: void (the state tax gets updated by reference)
  492. //
  493. //**************************************************************
  494.  
  495. void calcStateTax (struct employee * emp_ptr, int theSize)
  496. {
  497. int i; // loop and array index
  498.  
  499. // calculate state tax based on where employee works
  500. for (i = 0; i < theSize; ++i)
  501. {
  502. // Make sure tax state is all uppercase
  503. emp_ptr->taxState[0] = toupper(emp_ptr->taxState[0]);
  504. emp_ptr->taxState[1] = toupper(emp_ptr->taxState[1]);
  505.  
  506. // calculate state tax based on where employee resides
  507. if (strcmp(emp_ptr->taxState, "MA") == 0)
  508. emp_ptr->stateTax = emp_ptr->grossPay * MA_TAX_RATE;
  509. else if (strcmp(emp_ptr->taxState, "VT") == 0)
  510. emp_ptr->stateTax = emp_ptr->grossPay * VT_TAX_RATE;
  511. else if (strcmp(emp_ptr->taxState, "NH") == 0)
  512. emp_ptr->stateTax = emp_ptr->grossPay * NH_TAX_RATE;
  513. else if (strcmp(emp_ptr->taxState, "CA") == 0)
  514. emp_ptr->stateTax = emp_ptr->grossPay * CA_TAX_RATE;
  515. else
  516. // any other state is the default rate
  517. emp_ptr->stateTax = emp_ptr->grossPay * DEFAULT_TAX_RATE;
  518.  
  519. // move to next employee
  520. ++emp_ptr;
  521. } // for
  522. } // calcStateTax
  523.  
  524. //*************************************************************
  525. // Function: calcFedTax
  526. //
  527. // Purpose: Calculates the Federal Tax owed based on the gross
  528. // pay for each employee
  529. //
  530. // Parameters:
  531. //
  532. // emp_ptr - pointer to the first element of an array of
  533. // employee structures (i.e., struct employee)
  534. // theSize - the array size (i.e., number of employees)
  535. //
  536. // Returns: void (the federal tax gets updated by reference)
  537. //
  538. //**************************************************************
  539.  
  540. void calcFedTax (struct employee *emp_ptr, int theSize)
  541. {
  542.  
  543. int i; // loop and array index
  544.  
  545. // calculate the federal tax for each employee
  546. for (i=0; i < theSize; ++i)
  547. {
  548. // Fed Tax is the same for all regardless of state
  549. emp_ptr->fedTax = emp_ptr->grossPay * FED_TAX_RATE;
  550.  
  551. // move to next employee
  552. emp_ptr++;
  553.  
  554. } // for
  555.  
  556. } // calcFedTax
  557.  
  558. //*************************************************************
  559. // Function: calcNetPay
  560. //
  561. // Purpose: Calculates the net pay as the gross pay minus any
  562. // state and federal taxes owed for each employee.
  563. // Essentially, their "take home" pay.
  564. //
  565. // Parameters:
  566. //
  567. // emp_ptr - pointer to array of employees (i.e., struct employee)
  568. // theSize - the array size (i.e., number of employees)
  569. //
  570. // Returns: void (the net pay gets updated by reference)
  571. //
  572. //**************************************************************
  573.  
  574. void calcNetPay (struct employee * emp_ptr, int theSize)
  575. {
  576. int i; // loop and array index
  577. float theTotalTaxes; // the total state and federal tax
  578.  
  579. // calculate the take home pay for each employee
  580. for (i = 0; i < theSize; ++i)
  581. {
  582. // calculate the total state and federal taxes
  583. theTotalTaxes = emp_ptr->stateTax + emp_ptr->fedTax;
  584.  
  585. // calculate the net pay
  586. emp_ptr->netPay = emp_ptr->grossPay - theTotalTaxes;
  587.  
  588. // move to next employee
  589. ++emp_ptr;
  590. } // for
  591. } // calcNetPay
  592.  
  593. //*************************************************************
  594. // Function: calcEmployeeTotals
  595. //
  596. // Purpose: Performs a running total (sum) of each employee
  597. // floating point member in the array of structures
  598. //
  599. // Parameters:
  600. //
  601. // emp_ptr - pointer to array of employees (structure)
  602. // emp_totals_ptr - pointer to a structure containing the
  603. // running totals of all floating point
  604. // members in the array of employee structure
  605. // that is accessed and referenced by emp_ptr
  606. // theSize - the array size (i.e., number of employees)
  607. //
  608. // Returns:
  609. //
  610. // void (the employeeTotals structure gets updated by reference)
  611. //
  612. //**************************************************************
  613.  
  614. void calcEmployeeTotals (struct employee * emp_ptr,
  615. struct totals * emp_totals_ptr,
  616. int theSize)
  617. {
  618.  
  619. int i; // loop index
  620.  
  621. // total up each floating point item for all employees
  622. for (i = 0; i < theSize; ++i)
  623. {
  624. // add current employee data to our running totals
  625. emp_totals_ptr->total_wageRate += emp_ptr->wageRate;
  626. emp_totals_ptr->total_hours += emp_ptr->hours;
  627. emp_totals_ptr->total_overtimeHrs += emp_ptr->overtimeHrs;
  628. emp_totals_ptr->total_grossPay += emp_ptr->grossPay;
  629. emp_totals_ptr->total_stateTax += emp_ptr->stateTax;
  630. emp_totals_ptr->total_fedTax += emp_ptr->fedTax;
  631. emp_totals_ptr->total_netPay += emp_ptr->netPay;
  632.  
  633. // go to next employee in our array of structures
  634. // Note: We don't need to increment the emp_totals_ptr
  635. // because it is not an array
  636. ++emp_ptr;
  637.  
  638. } // for
  639.  
  640. // no need to return anything since we used pointers and have
  641. // been referring the array of employee structure and the
  642. // the total structure from its calling function ... this
  643. // is the power of Call by Reference.
  644.  
  645. } // calcEmployeeTotals
  646.  
  647. //*************************************************************
  648. // Function: calcEmployeeMinMax
  649. //
  650. // Purpose: Accepts various floating point values from an
  651. // employee and adds to a running update of min
  652. // and max values
  653. //
  654. // Parameters:
  655. //
  656. // employeeData - array of employees (i.e., struct employee)
  657. // employeeTotals - structure containing a running totals
  658. // of all fields above
  659. // theSize - the array size (i.e., number of employees)
  660. //
  661. // Returns:
  662. //
  663. // employeeMinMax - updated employeeMinMax structure
  664. //
  665. //**************************************************************
  666.  
  667. void calcEmployeeMinMax (struct employee * emp_ptr,
  668. struct min_max * emp_minMax_ptr,
  669. int theSize)
  670. {
  671.  
  672. int i; // loop index
  673.  
  674. // set the min to the first employee members
  675. emp_minMax_ptr->min_wageRate = emp_ptr->wageRate;
  676. emp_minMax_ptr->min_hours = emp_ptr->hours;
  677. emp_minMax_ptr->min_overtimeHrs = emp_ptr->overtimeHrs;
  678. emp_minMax_ptr->min_grossPay = emp_ptr->grossPay;
  679. emp_minMax_ptr->min_stateTax = emp_ptr->stateTax;
  680. emp_minMax_ptr->min_fedTax = emp_ptr->fedTax;
  681. emp_minMax_ptr->min_netPay = emp_ptr->netPay;
  682.  
  683. // set the max to the first employee members
  684. emp_minMax_ptr->max_wageRate = emp_ptr->wageRate;
  685. emp_minMax_ptr->max_hours = emp_ptr->hours;
  686. emp_minMax_ptr->max_overtimeHrs = emp_ptr->overtimeHrs;
  687. emp_minMax_ptr->max_grossPay = emp_ptr->grossPay;
  688. emp_minMax_ptr->max_stateTax = emp_ptr->stateTax;
  689. emp_minMax_ptr->max_fedTax = emp_ptr->fedTax;
  690. emp_minMax_ptr->max_netPay = emp_ptr->netPay;
  691.  
  692. // compare the rest of the employees to each other for min and max
  693. for (i = 1; i < theSize; ++i)
  694. {
  695.  
  696. // go to next employee in our array of structures
  697. // Note: We don't need to increment the emp_totals_ptr
  698. // because it is not an array
  699. ++emp_ptr;
  700.  
  701. // check if current Wage Rate is the new min and/or max
  702. if (emp_ptr->wageRate < emp_minMax_ptr->min_wageRate)
  703. {
  704. emp_minMax_ptr->min_wageRate = emp_ptr->wageRate;
  705. }
  706.  
  707. if (emp_ptr->wageRate > emp_minMax_ptr->max_wageRate)
  708. {
  709. emp_minMax_ptr->max_wageRate = emp_ptr->wageRate;
  710. }
  711.  
  712. // check if current Hours is the new min and/or max
  713. if (emp_ptr->hours < emp_minMax_ptr->min_hours)
  714. {
  715. emp_minMax_ptr->min_hours = emp_ptr->hours;
  716. }
  717.  
  718. if (emp_ptr->hours > emp_minMax_ptr->max_hours)
  719. {
  720. emp_minMax_ptr->max_hours = emp_ptr->hours;
  721. }
  722.  
  723. // check if current Overtime Hours is the new min and/or max
  724. if (emp_ptr->overtimeHrs < emp_minMax_ptr->min_overtimeHrs)
  725. {
  726. emp_minMax_ptr->min_overtimeHrs = emp_ptr->overtimeHrs;
  727. }
  728.  
  729. if (emp_ptr->overtimeHrs > emp_minMax_ptr->max_overtimeHrs)
  730. {
  731. emp_minMax_ptr->max_overtimeHrs = emp_ptr->overtimeHrs;
  732. }
  733.  
  734. // check if current Gross Pay is the new min and/or max
  735. if (emp_ptr->grossPay < emp_minMax_ptr->min_grossPay)
  736. {
  737. emp_minMax_ptr->min_grossPay = emp_ptr->grossPay;
  738. }
  739.  
  740. if (emp_ptr->grossPay > emp_minMax_ptr->max_grossPay)
  741. {
  742. emp_minMax_ptr->max_grossPay = emp_ptr->grossPay;
  743. }
  744.  
  745. // check if current State Tax is the new min and/or max
  746. if (emp_ptr->stateTax < emp_minMax_ptr->min_stateTax)
  747. {
  748. emp_minMax_ptr->min_stateTax = emp_ptr->stateTax;
  749. }
  750.  
  751. if (emp_ptr->stateTax > emp_minMax_ptr->max_stateTax)
  752. {
  753. emp_minMax_ptr->max_stateTax = emp_ptr->stateTax;
  754. }
  755.  
  756. // check if current Federal Tax is the new min and/or max
  757. if (emp_ptr->fedTax < emp_minMax_ptr->min_fedTax)
  758. {
  759. emp_minMax_ptr->min_fedTax = emp_ptr->fedTax;
  760. }
  761.  
  762. if (emp_ptr->fedTax > emp_minMax_ptr->max_fedTax)
  763. {
  764. emp_minMax_ptr->max_fedTax = emp_ptr->fedTax;
  765. }
  766.  
  767. // check if current Net Pay is the new min and/or max
  768. if (emp_ptr->netPay < emp_minMax_ptr->min_netPay)
  769. {
  770. emp_minMax_ptr->min_netPay = emp_ptr->netPay;
  771. }
  772.  
  773. if (emp_ptr->netPay > emp_minMax_ptr->max_netPay)
  774. {
  775. emp_minMax_ptr->max_netPay = emp_ptr->netPay;
  776. }
  777.  
  778. } // else if
  779.  
  780. } // calcEmployeeMinMax
  781.  
Success #stdin #stdout 0.01s 5328KB
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