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