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