fork(1) download
  1. //********************************************************
  2. //
  3. // Assignment 8 - Structures and Strings and Pointers
  4. //
  5. // Name: Heather Grothe
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: April 2, 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. // 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. // ... note how one could easily extend this to other parts
  48. // parts of a name: Middle, Nickname, Prefix, Suffix, etc.
  49. struct name
  50. {
  51. char firstName[FIRST_NAME_SIZE];
  52. char lastName [LAST_NAME_SIZE];
  53. };
  54.  
  55. // Define a structure type to pass employee data between functions
  56. // Note that the structure type is global, but you don't want a variable
  57. // of that type to be global. Best to declare a variable of that type
  58. // in a function like main or another function and pass as needed.
  59. struct employee
  60. {
  61. struct name empName;
  62. char taxState [TAX_STATE_SIZE];
  63. long int clockNumber;
  64. float wageRate;
  65. float hours;
  66. float overtimeHrs;
  67. float grossPay;
  68. float stateTax;
  69. float fedTax;
  70. float netPay;
  71. };
  72.  
  73. // this structure type defines the totals of all floating point items
  74. // so they can be totaled and used also to calculate averages
  75. struct totals
  76. {
  77. float total_wageRate;
  78. float total_hours;
  79. float total_overtimeHrs;
  80. float total_grossPay;
  81. float total_stateTax;
  82. float total_fedTax;
  83. float total_netPay;
  84. };
  85.  
  86. // this structure type defines the min and max values of all floating
  87. // point items so they can be display in our final report
  88. struct min_max
  89. {
  90. float min_wageRate;
  91. float min_hours;
  92. float min_overtimeHrs;
  93. float min_grossPay;
  94. float min_stateTax;
  95. float min_fedTax;
  96. float min_netPay;
  97. float max_wageRate;
  98. float max_hours;
  99. float max_overtimeHrs;
  100. float max_grossPay;
  101. float max_stateTax;
  102. float max_fedTax;
  103. float max_netPay;
  104. };
  105.  
  106. // define prototypes here for each function except main
  107.  
  108. // These prototypes have already been transitioned to pointers
  109. void getHours (struct employee * emp_ptr, int theSize);
  110. void printEmp (struct employee * emp_ptr, int theSize);
  111.  
  112. void calcEmployeeTotals (struct employee * emp_ptr,
  113. struct totals * emp_totals_ptr,
  114. int theSize);
  115.  
  116. void calcEmployeeMinMax (struct employee * emp_ptr,
  117. struct min_max * emp_MinMax_ptr,
  118. int theSize);
  119.  
  120. // This prototype does not need to use pointers
  121. void printHeader (void);
  122.  
  123. // transitioned prototypes
  124. void calcOvertimeHrs (struct employee * emp_ptr, int theSize);
  125. void calcGrossPay (struct employee * emp_ptr, int theSize);
  126. void calcStateTax (struct employee * emp_ptr, int theSize);
  127. void calcFedTax (struct employee * emp_ptr, int theSize);
  128. void calcNetPay (struct employee * emp_ptr, int theSize);
  129. void printEmpStatistics (struct totals * emp_totals_ptr,
  130. struct min_max * emp_MinMax_ptr,
  131. int theSize);
  132.  
  133. int main ()
  134. {
  135.  
  136. // Set up a local variable to store the employee information
  137. // Initialize the name, tax state, clock number, and wage rate
  138. struct employee employeeData[SIZE] = {
  139. { {"Connie", "Cobol"}, "MA", 98401, 10.60},
  140. { {"Mary", "Apl"}, "NH", 526488, 9.75 },
  141. { {"Frank", "Fortran"}, "VT", 765349, 10.50 },
  142. { {"Jeff", "Ada"}, "NY", 34645, 12.25 },
  143. { {"Anton", "Pascal"},"CA",127615, 8.35 }
  144. };
  145.  
  146. // declare a pointer to the array of employee structures
  147. struct employee * emp_ptr;
  148.  
  149. // set the pointer to point to the array of employees
  150. emp_ptr = employeeData;
  151.  
  152. // set up structure to store totals and initialize all to zero
  153. struct totals employeeTotals = {0,0,0,0,0,0,0};
  154.  
  155. // pointer to the employeeTotals structure
  156. struct totals * emp_totals_ptr = &employeeTotals;
  157.  
  158. // set up structure to store min and max values and initialize all to zero
  159. struct min_max employeeMinMax = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  160.  
  161. // pointer to the employeeMinMax structure
  162. struct min_max * emp_minMax_ptr = &employeeMinMax;
  163.  
  164. // Call functions as needed to read and calculate information
  165.  
  166. // Prompt for the number of hours worked by the employee
  167. getHours (emp_ptr, SIZE);
  168.  
  169. // Calculate the overtime hours
  170. calcOvertimeHrs (emp_ptr, SIZE);
  171.  
  172. // Calculate the weekly gross pay
  173. calcGrossPay (emp_ptr, SIZE);
  174.  
  175. // Calculate the state tax
  176. calcStateTax (emp_ptr, SIZE);
  177.  
  178. // Calculate the federal tax
  179. calcFedTax (emp_ptr, SIZE);
  180.  
  181. // Calculate the net pay after taxes
  182. calcNetPay (emp_ptr, SIZE);
  183.  
  184. // Keep a running sum of the employee totals
  185. calcEmployeeTotals (emp_ptr,
  186. emp_totals_ptr,
  187. SIZE);
  188.  
  189. // Keep a running update of the employee minimum and maximum values
  190. calcEmployeeMinMax (emp_ptr,
  191. emp_minMax_ptr,
  192. SIZE);
  193.  
  194. // Print the column headers
  195. printHeader();
  196.  
  197. // print out final information on each employee
  198. printEmp (emp_ptr, SIZE);
  199.  
  200. // print the totals and averages for all float items
  201. printEmpStatistics (emp_totals_ptr,
  202. emp_minMax_ptr,
  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. // While you could just print the first and last name in the printf
  299. // statement that follows, you could also use various C string library
  300. // functions to format the name exactly the way you want it. Breaking
  301. // the name into first and last members additionally gives you some
  302. // flexibility in printing. This also becomes more useful if we decide
  303. // later to store other parts of a person's name. I really did this just
  304. // to show you how to work with some of the common string functions.
  305. strcpy (name, emp_ptr->empName.firstName);
  306. strcat (name, " "); // add a space between first and last names
  307. strcat (name, emp_ptr->empName.lastName);
  308.  
  309. // Print out a single employee
  310. printf("\n%-20.20s %-2.2s %06li %5.2f %4.1f %4.1f %7.2f %6.2f %7.2f %8.2f",
  311. name, emp_ptr->taxState, emp_ptr->clockNumber,
  312. emp_ptr->wageRate, emp_ptr->hours,
  313. emp_ptr->overtimeHrs, emp_ptr->grossPay,
  314. emp_ptr->stateTax, emp_ptr->fedTax,
  315. emp_ptr->netPay);
  316.  
  317. // set pointer to next employee
  318. ++emp_ptr;
  319.  
  320. } // for
  321.  
  322. } // printEmp
  323.  
  324. //*************************************************************
  325. // Function: printEmpStatistics
  326. //
  327. // Purpose: Prints out the summary totals and averages of all
  328. // floating point value items for all employees
  329. // that have been processed. It also prints
  330. // out the min and max values.
  331. //
  332. // Parameters:
  333. //
  334. // emp_totals_ptr - pointer to a structure containing a running total
  335. // of all employee floating point items
  336. // emp_MinMax_ptr - pointer to a structure containing all the minimum
  337. // and maximum values of all employee
  338. // floating point items
  339. // theSize - the total number of employees processed, used
  340. // to check for zero or negative divide condition.
  341. //
  342. // Returns: void
  343. //
  344. //**************************************************************
  345.  
  346. void printEmpStatistics (struct totals * emp_totals_ptr,
  347. struct min_max * emp_MinMax_ptr,
  348. int theSize)
  349. {
  350.  
  351. // print a separator line
  352. printf("\n--------------------------------------------------------------");
  353. printf("-------------------");
  354.  
  355. // print the totals for all the floating point fields
  356. printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  357. emp_totals_ptr->total_wageRate,
  358. emp_totals_ptr->total_hours,
  359. emp_totals_ptr->total_overtimeHrs,
  360. emp_totals_ptr->total_grossPay,
  361. emp_totals_ptr->total_stateTax,
  362. emp_totals_ptr->total_fedTax,
  363. emp_totals_ptr->total_netPay);
  364.  
  365. // make sure you don't divide by zero or a negative number
  366. if (theSize > 0)
  367. {
  368. // print the averages for all the floating point fields
  369. printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  370. emp_totals_ptr->total_wageRate/theSize,
  371. emp_totals_ptr->total_hours/theSize,
  372. emp_totals_ptr->total_overtimeHrs/theSize,
  373. emp_totals_ptr->total_grossPay/theSize,
  374. emp_totals_ptr->total_stateTax/theSize,
  375. emp_totals_ptr->total_fedTax/theSize,
  376. emp_totals_ptr->total_netPay/theSize);
  377. } // if
  378.  
  379. // print the min and max values
  380.  
  381. printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  382. emp_MinMax_ptr->min_wageRate,
  383. emp_MinMax_ptr->min_hours,
  384. emp_MinMax_ptr->min_overtimeHrs,
  385. emp_MinMax_ptr->min_grossPay,
  386. emp_MinMax_ptr->min_stateTax,
  387. emp_MinMax_ptr->min_fedTax,
  388. emp_MinMax_ptr->min_netPay);
  389.  
  390. printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  391. emp_MinMax_ptr->max_wageRate,
  392. emp_MinMax_ptr->max_hours,
  393. emp_MinMax_ptr->max_overtimeHrs,
  394. emp_MinMax_ptr->max_grossPay,
  395. emp_MinMax_ptr->max_stateTax,
  396. emp_MinMax_ptr->max_fedTax,
  397. emp_MinMax_ptr->max_netPay);
  398.  
  399. } // printEmpStatistics
  400.  
  401. //*************************************************************
  402. // Function: calcOvertimeHrs
  403. //
  404. // Purpose: Calculates the overtime hours worked by an employee
  405. // in a given week for each employee.
  406. //
  407. // Parameters:
  408. //
  409. // emp_ptr - pointer to array of employees (i.e., struct employee)
  410. // theSize - the array size (i.e., number of employees)
  411. //
  412. // Returns: void (the overtime hours gets updated by reference)
  413. //
  414. //**************************************************************
  415.  
  416. void calcOvertimeHrs (struct employee * emp_ptr, int theSize)
  417. {
  418.  
  419. int i; // array and loop index
  420.  
  421. // calculate overtime hours for each employee
  422. for (i = 0; i < theSize; ++i)
  423. {
  424. if (emp_ptr->hours >= STD_HOURS)
  425. {
  426. emp_ptr->overtimeHrs = emp_ptr->hours - STD_HOURS;
  427. }//if
  428. else
  429. {
  430. emp_ptr->overtimeHrs = 0;
  431. }//else
  432.  
  433. //increment pointer
  434. ++emp_ptr;
  435.  
  436. } // for
  437.  
  438. } // calcOvertimeHrs
  439.  
  440. //*************************************************************
  441. // Function: calcGrossPay
  442. //
  443. // Purpose: Calculates the gross pay based on the the normal pay
  444. // and any overtime pay for a given week for each
  445. // employee.
  446. //
  447. // Parameters:
  448. //
  449. // emp_ptr - pointer to array of employees (i.e., struct employee)
  450. // theSize - the array size (i.e., number of employees)
  451. //
  452. // Returns: void (the gross pay gets updated by reference)
  453. //
  454. //**************************************************************
  455.  
  456. void calcGrossPay (struct employee * emp_ptr, int theSize)
  457. {
  458. int i; // loop and array index
  459. float theNormalPay; // normal pay without any overtime hours
  460. float theOvertimePay; // overtime pay
  461.  
  462. // calculate grossPay for each employee
  463. for (i=0; i < theSize; ++i)
  464. {
  465. // calculate normal pay and any overtime pay
  466. theNormalPay = emp_ptr->wageRate * (emp_ptr->hours - emp_ptr->overtimeHrs);
  467. theOvertimePay = emp_ptr->overtimeHrs * (OT_RATE * emp_ptr->wageRate);
  468.  
  469. // calculate gross pay for employee as normalPay + any overtime pay
  470. emp_ptr->grossPay = theNormalPay + theOvertimePay;
  471.  
  472. // set pointer to next employee
  473. ++emp_ptr;
  474. }//for
  475.  
  476. } // calcGrossPay
  477.  
  478. //*************************************************************
  479. // Function: calcStateTax
  480. //
  481. // Purpose: Calculates the State Tax owed based on gross pay
  482. // for each employee. State tax rate is based on the
  483. // the designated tax state based on where the
  484. // employee is actually performing the work. Each
  485. // state decides their tax rate.
  486. //
  487. // Parameters:
  488. //
  489. // emp_ptr - pointer to array of employees (i.e., struct employee)
  490. // theSize - the array size (i.e., number of employees)
  491. //
  492. // Returns: void (the state tax gets updated by reference)
  493. //
  494. //**************************************************************
  495.  
  496. void calcStateTax (struct employee * emp_ptr, int theSize)
  497. {
  498.  
  499. int i; // loop and array index
  500.  
  501. // calculate state tax based on where employee works
  502. for (i=0; i < theSize; ++i)
  503. {
  504. // Make sure tax state is all uppercase
  505. if (islower(emp_ptr->taxState[0]))
  506. {
  507. emp_ptr->taxState[0] = toupper(emp_ptr->taxState[0]);
  508. }//if
  509. if (islower(emp_ptr->taxState[1]))
  510. {
  511. emp_ptr->taxState[1] = toupper(emp_ptr->taxState[1]);
  512. }//if
  513.  
  514. // calculate state tax based on where employee resides
  515. if (strcmp(emp_ptr->taxState, "MA") == 0)
  516. {
  517. emp_ptr->stateTax = emp_ptr->grossPay * MA_TAX_RATE;
  518. }//if
  519. else if (strcmp(emp_ptr->taxState, "VT") == 0)
  520. {
  521. emp_ptr->stateTax = emp_ptr->grossPay * VT_TAX_RATE;
  522. }//else if
  523. else if (strcmp(emp_ptr->taxState, "NH") == 0)
  524. {
  525. emp_ptr->stateTax = emp_ptr->grossPay * NH_TAX_RATE;
  526. }//else if
  527. else if (strcmp(emp_ptr->taxState, "CA") == 0)
  528. {
  529. emp_ptr->stateTax = emp_ptr->grossPay * CA_TAX_RATE;
  530. }//else if
  531. else
  532. {
  533. // any other state is the default rate
  534. emp_ptr->stateTax = emp_ptr->grossPay * DEFAULT_TAX_RATE;
  535. }//else
  536.  
  537. // set pointer to next employee
  538. ++emp_ptr;
  539. } // for
  540.  
  541. } // calcStateTax
  542.  
  543. //*************************************************************
  544. // Function: calcFedTax
  545. //
  546. // Purpose: Calculates the Federal Tax owed based on the gross
  547. // pay for each employee
  548. //
  549. // Parameters:
  550. //
  551. // emp_ptr - pointer to array of employees (i.e., struct employee)
  552. // theSize - the array size (i.e., number of employees)
  553. //
  554. // Returns: void (the federal tax gets updated by reference)
  555. //
  556. //**************************************************************
  557.  
  558. void calcFedTax (struct employee * emp_ptr, int theSize)
  559. {
  560.  
  561. int i; // loop and array index
  562.  
  563. // calculate the federal tax for each employee
  564. for (i=0; i < theSize; ++i)
  565. {
  566. // Fed Tax is the same for all regardless of state
  567. emp_ptr->fedTax = emp_ptr->grossPay * FED_TAX_RATE;
  568.  
  569. // set pointer to next employee
  570. ++emp_ptr;
  571.  
  572. } // for
  573.  
  574. } // calcFedTax
  575.  
  576. //*************************************************************
  577. // Function: calcNetPay
  578. //
  579. // Purpose: Calculates the net pay as the gross pay minus any
  580. // state and federal taxes owed for each employee.
  581. // Essentially, their "take home" pay.
  582. //
  583. // Parameters:
  584. //
  585. // emp_ptr - pointer to array of employees (i.e., struct employee)
  586. // theSize - the array size (i.e., number of employees)
  587. //
  588. // Returns: void (the net pay gets updated by reference)
  589. //
  590. //**************************************************************
  591.  
  592. void calcNetPay (struct employee * emp_ptr, int theSize)
  593. {
  594. int i; // loop and array index
  595. float theTotalTaxes; // the total state and federal tax
  596.  
  597. // calculate the take home pay for each employee
  598. for (i=0; i < theSize; ++i)
  599. {
  600. // calculate the total state and federal taxes
  601. theTotalTaxes = emp_ptr->stateTax + emp_ptr->fedTax;
  602.  
  603. // calculate the net pay
  604. emp_ptr->netPay = emp_ptr->grossPay - theTotalTaxes;
  605.  
  606. // set pointer to next employee
  607. ++emp_ptr;
  608.  
  609. } // for
  610.  
  611. } // calcNetPay
  612.  
  613. //*************************************************************
  614. // Function: calcEmployeeTotals
  615. //
  616. // Purpose: Performs a running total (sum) of each employee
  617. // floating point member in the array of structures
  618. //
  619. // Parameters:
  620. //
  621. // emp_ptr - pointer to array of employees (structure)
  622. // emp_totals_ptr - pointer to a structure containing the
  623. // running totals of all floating point
  624. // members in the array of employee structure
  625. // that is accessed and referenced by emp_ptr
  626. // theSize - the array size (i.e., number of employees)
  627. //
  628. // Returns:
  629. //
  630. // void (the employeeTotals structure gets updated by reference)
  631. //
  632. //**************************************************************
  633.  
  634. void calcEmployeeTotals (struct employee * emp_ptr,
  635. struct totals * emp_totals_ptr,
  636. int theSize)
  637. {
  638.  
  639. int i; // loop index
  640.  
  641. // total up each floating point item for all employees
  642. for (i = 0; i < theSize; ++i)
  643. {
  644. // add current employee data to our running totals
  645. emp_totals_ptr->total_wageRate += emp_ptr->wageRate;
  646. emp_totals_ptr->total_hours += emp_ptr->hours;
  647. emp_totals_ptr->total_overtimeHrs += emp_ptr->overtimeHrs;
  648. emp_totals_ptr->total_grossPay += emp_ptr->grossPay;
  649. emp_totals_ptr->total_stateTax += emp_ptr->stateTax;
  650. emp_totals_ptr->total_fedTax += emp_ptr->fedTax;
  651. emp_totals_ptr->total_netPay += emp_ptr->netPay;
  652.  
  653. // go to next employee in our array of structures
  654. ++emp_ptr;
  655.  
  656. } // for
  657.  
  658. } // calcEmployeeTotals
  659.  
  660. //*************************************************************
  661. // Function: calcEmployeeMinMax
  662. //
  663. // Purpose: Accepts various floating point values from an
  664. // employee and adds to a running update of min
  665. // and max values
  666. //
  667. // Parameters:
  668. //
  669. // employeeData - array of employees (i.e., struct employee)
  670. // employeeTotals - structure containing a running totals
  671. // of all fields above
  672. // theSize - the array size (i.e., number of employees)
  673. //
  674. // Returns:
  675. //
  676. // employeeMinMax - updated employeeMinMax structure
  677. //
  678. //**************************************************************
  679.  
  680. void calcEmployeeMinMax (struct employee * emp_ptr,
  681. struct min_max * emp_minMax_ptr,
  682. int theSize)
  683. {
  684.  
  685. int i; // loop index
  686.  
  687. // set the min to the first employee members
  688. emp_minMax_ptr->min_wageRate = emp_ptr->wageRate;
  689. emp_minMax_ptr->min_hours = emp_ptr->hours;
  690. emp_minMax_ptr->min_overtimeHrs = emp_ptr->overtimeHrs;
  691. emp_minMax_ptr->min_grossPay = emp_ptr->grossPay;
  692. emp_minMax_ptr->min_stateTax = emp_ptr->stateTax;
  693. emp_minMax_ptr->min_fedTax = emp_ptr->fedTax;
  694. emp_minMax_ptr->min_netPay = emp_ptr->netPay;
  695.  
  696. // set the max to the first employee members
  697. emp_minMax_ptr->max_wageRate = emp_ptr->wageRate;
  698. emp_minMax_ptr->max_hours = emp_ptr->hours;
  699. emp_minMax_ptr->max_overtimeHrs = emp_ptr->overtimeHrs;
  700. emp_minMax_ptr->max_grossPay = emp_ptr->grossPay;
  701. emp_minMax_ptr->max_stateTax = emp_ptr->stateTax;
  702. emp_minMax_ptr->max_fedTax = emp_ptr->fedTax;
  703. emp_minMax_ptr->max_netPay = emp_ptr->netPay;
  704.  
  705. // compare the rest of the employees to each other for min and max
  706. for (i = 1; i < theSize; ++i)
  707. {
  708. // go to next employee in our array of structures
  709. ++emp_ptr;
  710.  
  711. // check if current Wage Rate is the new min and/or max
  712. if (emp_ptr->wageRate < emp_minMax_ptr->min_wageRate)
  713. {
  714. emp_minMax_ptr->min_wageRate = emp_ptr->wageRate;
  715. }//if
  716.  
  717. if (emp_ptr->wageRate > emp_minMax_ptr->max_wageRate)
  718. {
  719. emp_minMax_ptr->max_wageRate = emp_ptr->wageRate;
  720. }//if
  721.  
  722. // check is current Hours is the new min and/or max
  723. if (emp_ptr->hours < emp_minMax_ptr->min_hours)
  724. {
  725. emp_minMax_ptr->min_hours = emp_ptr->hours;
  726. }//if
  727.  
  728. if (emp_ptr->hours > emp_minMax_ptr->max_hours)
  729. {
  730. emp_minMax_ptr->max_hours = emp_ptr->hours;
  731. }//if
  732.  
  733. // check is current Overtime Hours is the new min and/or max
  734. if (emp_ptr->overtimeHrs < emp_minMax_ptr->min_overtimeHrs)
  735. {
  736. emp_minMax_ptr->min_overtimeHrs = emp_ptr->overtimeHrs;
  737. }//if
  738.  
  739. if (emp_ptr->overtimeHrs > emp_minMax_ptr->max_overtimeHrs)
  740. {
  741. emp_minMax_ptr->max_overtimeHrs = emp_ptr->overtimeHrs;
  742. }//if
  743.  
  744. // check is current Gross Pay is the new min and/or max
  745. if (emp_ptr->grossPay < emp_minMax_ptr->min_grossPay)
  746. {
  747. emp_minMax_ptr->min_grossPay = emp_ptr->grossPay;
  748. }//if
  749.  
  750. if (emp_ptr->grossPay > emp_minMax_ptr->max_grossPay)
  751. {
  752. emp_minMax_ptr->max_grossPay = emp_ptr->grossPay;
  753. }//if
  754.  
  755. // check is current State Tax is the new min and/or max
  756. if (emp_ptr->stateTax < emp_minMax_ptr->min_stateTax)
  757. {
  758. emp_minMax_ptr->min_stateTax = emp_ptr->stateTax;
  759. }//if
  760.  
  761. if (emp_ptr->stateTax > emp_minMax_ptr->max_stateTax)
  762. {
  763. emp_minMax_ptr->max_stateTax = emp_ptr->stateTax;
  764. }//if
  765.  
  766. // check is current Federal Tax is the new min and/or max
  767. if (emp_ptr->fedTax < emp_minMax_ptr->min_fedTax)
  768. {
  769. emp_minMax_ptr->min_fedTax = emp_ptr->fedTax;
  770. }//if
  771.  
  772. if (emp_ptr->fedTax > emp_minMax_ptr->max_fedTax)
  773. {
  774. emp_minMax_ptr->max_fedTax = emp_ptr->fedTax;
  775. }//if
  776.  
  777. // check is current Net Pay is the new min and/or max
  778. if (emp_ptr->netPay < emp_minMax_ptr->min_netPay)
  779. {
  780. emp_minMax_ptr->min_netPay = emp_ptr->netPay;
  781. }//if
  782.  
  783. if (emp_ptr->netPay > emp_minMax_ptr->max_netPay)
  784. {
  785. emp_minMax_ptr->max_netPay = emp_ptr->netPay;
  786. }//if
  787.  
  788. } // for
  789.  
  790. } // calcEmployeeMinMax
Success #stdin #stdout 0s 5316KB
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