fork download
  1. //********************************************************
  2. //
  3. // Assignment 8 - Structures and Strings and Pointers
  4. //
  5. // Name: Timothy Stockton
  6. //
  7. // Class: C Programming, Summer 2025
  8. //
  9. // Date: July 17th, 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. // ... note how one could easily extend this to other
  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. void getHours (struct employee * emp_ptr, int theSize);
  109. void printEmp (struct employee * emp_ptr, int theSize);
  110.  
  111. void calcEmployeeTotals (struct employee * emp_ptr,
  112. struct totals * emp_totals_ptr,
  113. int theSize);
  114.  
  115. void calcEmployeeMinMax (struct employee * emp_ptr,
  116. struct min_max * emp_MinMax_ptr,
  117. int theSize);
  118.  
  119. void printHeader (void);
  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. // Note the & to specify the address of the employeeTotals
  184. // structure. Needed since pointers work with addresses.
  185. calcEmployeeTotals (employeeData,
  186. &employeeTotals,
  187. SIZE);
  188.  
  189. // Keep a running update of the employee minimum and maximum values
  190. calcEmployeeMinMax (employeeData,
  191. &employeeMinMax,
  192. SIZE);
  193.  
  194. // Print the output table column headers
  195. printHeader();
  196.  
  197. // print out final information on each employee
  198. printEmp (employeeData, SIZE);
  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. // 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.
  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 a structure containing a running total
  334. // of all employee floating point items
  335. // emp_MinMax_ptr - pointer to a structure containing all the minimum
  336. // and maximum values of all employee
  337. // floating point items
  338. // theSize - the total number of employees processed, used
  339. // to check for zero or negative divide condition.
  340. //
  341. // Returns: void
  342. //
  343. //**************************************************************
  344.  
  345. void printEmpStatistics (struct totals * emp_totals_ptr,
  346. struct min_max * emp_MinMax_ptr,
  347. int theSize)
  348. {
  349.  
  350. // print a separator line
  351. printf("\n--------------------------------------------------------------");
  352. printf("-------------------");
  353.  
  354. // print the totals for all the floating point fields
  355. printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  356. emp_totals_ptr->total_wageRate,
  357. emp_totals_ptr->total_hours,
  358. emp_totals_ptr->total_overtimeHrs,
  359. emp_totals_ptr->total_grossPay,
  360. emp_totals_ptr->total_stateTax,
  361. emp_totals_ptr->total_fedTax,
  362. emp_totals_ptr->total_netPay);
  363.  
  364. // make sure you don't divide by zero or a negative number
  365. if (theSize > 0)
  366. {
  367. // print the averages for all the floating point fields
  368. printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  369. emp_totals_ptr->total_wageRate/theSize,
  370. emp_totals_ptr->total_hours/theSize,
  371. emp_totals_ptr->total_overtimeHrs/theSize,
  372. emp_totals_ptr->total_grossPay/theSize,
  373. emp_totals_ptr->total_stateTax/theSize,
  374. emp_totals_ptr->total_fedTax/theSize,
  375. emp_totals_ptr->total_netPay/theSize);
  376. } // if
  377.  
  378. // print the min and max values
  379.  
  380. printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  381. emp_MinMax_ptr->min_wageRate,
  382. emp_MinMax_ptr->min_hours,
  383. emp_MinMax_ptr->min_overtimeHrs,
  384. emp_MinMax_ptr->min_grossPay,
  385. emp_MinMax_ptr->min_stateTax,
  386. emp_MinMax_ptr->min_fedTax,
  387. emp_MinMax_ptr->min_netPay);
  388.  
  389. printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  390. emp_MinMax_ptr->max_wageRate,
  391. emp_MinMax_ptr->max_hours,
  392. emp_MinMax_ptr->max_overtimeHrs,
  393. emp_MinMax_ptr->max_grossPay,
  394. emp_MinMax_ptr->max_stateTax,
  395. emp_MinMax_ptr->max_fedTax,
  396. emp_MinMax_ptr->max_netPay);
  397.  
  398. } // printEmpStatistics
  399.  
  400. //*************************************************************
  401. // Function: calcOvertimeHrs
  402. //
  403. // Purpose: Calculates the overtime hours worked by an employee
  404. // in a given week for each employee.
  405. //
  406. // Parameters:
  407. //
  408. // emp_ptr - pointer to array of employees (i.e., struct employee)
  409. // theSize - the array size (i.e., number of employees)
  410. //
  411. // Returns: void (the overtime hours gets updated by reference)
  412. //
  413. //**************************************************************
  414.  
  415. void calcOvertimeHrs (struct employee * emp_ptr, int theSize)
  416. {
  417.  
  418. int i; // loop index
  419.  
  420. // calculate overtime hours for each employee
  421. for (i = 0; i < theSize; ++i)
  422. {
  423. // Any overtime ?
  424. if (emp_ptr->hours >= STD_HOURS)
  425. {
  426. emp_ptr->overtimeHrs = emp_ptr->hours - STD_HOURS;
  427. }
  428. else // no overtime
  429. {
  430. emp_ptr->overtimeHrs = 0;
  431. }
  432.  
  433. ++emp_ptr; // next employee
  434.  
  435. } // for
  436.  
  437. } // calcOvertimeHrs
  438.  
  439. //*************************************************************
  440. // Function: calcGrossPay
  441. //
  442. // Purpose: Calculates the gross pay based on the the normal pay
  443. // and any overtime pay for a given week for each
  444. // employee.
  445. //
  446. // Parameters:
  447. //
  448. // emp_ptr - pointer to array of employees (i.e., struct employee)
  449. // theSize - the array size (i.e., number of employees)
  450. //
  451. // Returns: void (the gross pay gets updated by reference)
  452. //
  453. //**************************************************************
  454.  
  455. void calcGrossPay (struct employee * emp_ptr, int theSize)
  456. {
  457. int i; // loop index
  458. float theNormalPay; // normal pay without any overtime hours
  459. float theOvertimePay; // overtime pay
  460.  
  461. // calculate grossPay for each employee
  462. for (i=0; i < theSize; ++i)
  463. {
  464. // calculate normal pay and any overtime pay
  465. theNormalPay = emp_ptr->wageRate *
  466. (emp_ptr->hours - emp_ptr->overtimeHrs);
  467. theOvertimePay = emp_ptr->overtimeHrs *
  468. (OT_RATE * emp_ptr->wageRate);
  469.  
  470. // calculate gross pay for employee as normalPay + any overtime pay
  471. emp_ptr->grossPay = theNormalPay + theOvertimePay;
  472.  
  473. ++emp_ptr; // next employee
  474. }
  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 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. emp_ptr->taxState[0] = toupper(emp_ptr->taxState[0]);
  507. if (islower(emp_ptr->taxState[1]))
  508. emp_ptr->taxState[1] = toupper(emp_ptr->taxState[1]);
  509.  
  510. // calculate state tax based on where employee resides
  511. if (strcmp(emp_ptr->taxState, "MA") == 0)
  512. emp_ptr->stateTax = emp_ptr->grossPay * MA_TAX_RATE;
  513. else if (strcmp(emp_ptr->taxState, "VT") == 0)
  514. emp_ptr->stateTax = emp_ptr->grossPay * VT_TAX_RATE;
  515. else if (strcmp(emp_ptr->taxState, "NH") == 0)
  516. emp_ptr->stateTax = emp_ptr->grossPay * NH_TAX_RATE;
  517. else if (strcmp(emp_ptr->taxState, "CA") == 0)
  518. emp_ptr->stateTax = emp_ptr->grossPay * CA_TAX_RATE;
  519. else
  520. // any other state is the default rate
  521. emp_ptr->stateTax = emp_ptr->grossPay * DEFAULT_TAX_RATE;
  522.  
  523. ++emp_ptr; // next employee
  524. } // for
  525.  
  526. } // calcStateTax
  527.  
  528. //*************************************************************
  529. // Function: calcFedTax
  530. //
  531. // Purpose: Calculates the Federal Tax owed based on the gross
  532. // pay for each employee
  533. //
  534. // Parameters:
  535. //
  536. // emp_ptr - pointer to array of employees (i.e., struct employee)
  537. // theSize - the array size (i.e., number of employees)
  538. //
  539. // Returns: void (the federal tax gets updated by reference)
  540. //
  541. //**************************************************************
  542.  
  543. void calcFedTax (struct employee * emp_ptr, int theSize)
  544. {
  545.  
  546. int i; // loop index
  547.  
  548. // calculate the federal tax for each employee
  549. for (i=0; i < theSize; ++i)
  550. {
  551. // Fed Tax is the same for all regardless of state
  552. emp_ptr->fedTax = emp_ptr->grossPay * FED_TAX_RATE;
  553.  
  554. ++emp_ptr; // next employee
  555.  
  556. } // for
  557.  
  558. } // calcFedTax
  559.  
  560. //*************************************************************
  561. // Function: calcNetPay
  562. //
  563. // Purpose: Calculates the net pay as the gross pay minus any
  564. // state and federal taxes owed for each employee.
  565. // Essentially, their "take home" pay.
  566. //
  567. // Parameters:
  568. //
  569. // emp_ptr - pointer to array of employees (i.e., struct employee)
  570. // theSize - the array size (i.e., number of employees)
  571. //
  572. // Returns: void (the net pay gets updated by reference)
  573. //
  574. //**************************************************************
  575.  
  576. void calcNetPay (struct employee * emp_ptr, int theSize)
  577. {
  578. int i; // loop index
  579. float theTotalTaxes; // the total state and federal tax
  580.  
  581. // calculate the take home pay for each employee
  582. for (i=0; i < theSize; ++i)
  583. {
  584. // calculate the total state and federal taxes
  585. theTotalTaxes = emp_ptr->stateTax + emp_ptr->fedTax;
  586.  
  587. // calculate the net pay
  588. emp_ptr->netPay = emp_ptr->grossPay - theTotalTaxes;
  589.  
  590. ++emp_ptr; // next employee
  591.  
  592. } // for
  593.  
  594. } // calcNetPay
  595.  
  596. //*************************************************************
  597. // Function: calcEmployeeTotals
  598. //
  599. // Purpose: Performs a running total (sum) of each employee
  600. // floating point member in the array of structures
  601. //
  602. // Parameters:
  603. //
  604. // emp_ptr - pointer to array of employees (structure)
  605. // emp_totals_ptr - pointer to a structure containing the
  606. // running totals of all floating point
  607. // members in the array of employee structure
  608. // that is accessed and referenced by emp_ptr
  609. // theSize - the array size (i.e., number of employees)
  610. //
  611. // Returns:
  612. //
  613. // void (the employeeTotals structure gets updated by reference)
  614. //
  615. //**************************************************************
  616.  
  617. void calcEmployeeTotals (struct employee * emp_ptr,
  618. struct totals * emp_totals_ptr,
  619. int theSize)
  620. {
  621.  
  622. int i; // loop index
  623.  
  624. // total up each floating point item for all employees
  625. for (i = 0; i < theSize; ++i)
  626. {
  627. // add current employee data to our running totals
  628. emp_totals_ptr->total_wageRate += emp_ptr->wageRate;
  629. emp_totals_ptr->total_hours += emp_ptr->hours;
  630. emp_totals_ptr->total_overtimeHrs += emp_ptr->overtimeHrs;
  631. emp_totals_ptr->total_grossPay += emp_ptr->grossPay;
  632. emp_totals_ptr->total_stateTax += emp_ptr->stateTax;
  633. emp_totals_ptr->total_fedTax += emp_ptr->fedTax;
  634. emp_totals_ptr->total_netPay += emp_ptr->netPay;
  635.  
  636. // go to next employee in our array of structures
  637. // Note: We don't need to increment the emp_totals_ptr
  638. // because it is not an array
  639. ++emp_ptr;
  640.  
  641. } // for
  642.  
  643. // no need to return anything since we used pointers and have
  644. // been referring the array of employee structure and the
  645. // the total structure from its calling function ... this
  646. // is the power of Call by Reference.
  647.  
  648. } // calcEmployeeTotals
  649.  
  650. //*************************************************************
  651. // Function: calcEmployeeMinMax
  652. //
  653. // Purpose: Accepts various floating point values from an
  654. // employee and adds to a running update of min
  655. // and max values
  656. //
  657. // Parameters:
  658. //
  659. // emp_ptr - pointer to array of employees (i.e., struct employee)
  660. // emp_minMax_ptr - pointer to structure containing min and max
  661. // values of all floating point items
  662. // theSize - the array size (i.e., number of employees)
  663. //
  664. // Returns:
  665. //
  666. // void (updated by reference)
  667. //
  668. //**************************************************************
  669.  
  670. void calcEmployeeMinMax (struct employee * emp_ptr,
  671. struct min_max * emp_minMax_ptr,
  672. int theSize)
  673. {
  674.  
  675. int i; // loop index
  676.  
  677. // At this point, emp_ptr is pointing to the first
  678. // employee which is located in the first element
  679. // of our employee array of structures (employeeData).
  680.  
  681. // As this is the first employee, set each min
  682. // min and max value using our emp_minMax_ptr
  683. // to the associated member fields below. They
  684. // will become the initial baseline that we
  685. // can check and update if needed against the
  686. // remaining employees.
  687.  
  688. // set the min to the first employee members
  689. emp_minMax_ptr->min_wageRate = emp_ptr->wageRate;
  690. emp_minMax_ptr->min_hours = emp_ptr->hours;
  691. emp_minMax_ptr->min_overtimeHrs = emp_ptr->overtimeHrs;
  692. emp_minMax_ptr->min_grossPay = emp_ptr->grossPay;
  693. emp_minMax_ptr->min_stateTax = emp_ptr->stateTax;
  694. emp_minMax_ptr->min_fedTax = emp_ptr->fedTax;
  695. emp_minMax_ptr->min_netPay = emp_ptr->netPay;
  696.  
  697. // set the max to the first employee members
  698. emp_minMax_ptr->max_wageRate = emp_ptr->wageRate;
  699. emp_minMax_ptr->max_hours = emp_ptr->hours;
  700. emp_minMax_ptr->max_overtimeHrs = emp_ptr->overtimeHrs;
  701. emp_minMax_ptr->max_grossPay = emp_ptr->grossPay;
  702. emp_minMax_ptr->max_stateTax = emp_ptr->stateTax;
  703. emp_minMax_ptr->max_fedTax = emp_ptr->fedTax;
  704. emp_minMax_ptr->max_netPay = emp_ptr->netPay;
  705.  
  706. // compare the rest of the employees to each other for min and max
  707. for (i = 1; i < theSize; ++i)
  708. {
  709.  
  710. // go to next employee in our array of structures
  711. // Note: We don't need to increment the emp_minMax_ptr
  712. // because it is not an array
  713. ++emp_ptr;
  714.  
  715. // check if current Wage Rate is the new min and/or max
  716. if (emp_ptr->wageRate < emp_minMax_ptr->min_wageRate)
  717. {
  718. emp_minMax_ptr->min_wageRate = emp_ptr->wageRate;
  719. }
  720.  
  721. if (emp_ptr->wageRate > emp_minMax_ptr->max_wageRate)
  722. {
  723. emp_minMax_ptr->max_wageRate = emp_ptr->wageRate;
  724. }
  725.  
  726. // check is current Hours is the new min and/or max
  727. if (emp_ptr->hours < emp_minMax_ptr->min_hours)
  728. {
  729. emp_minMax_ptr->min_hours = emp_ptr->hours;
  730. }
  731.  
  732. if (emp_ptr->hours > emp_minMax_ptr->max_hours)
  733. {
  734. emp_minMax_ptr->max_hours = emp_ptr->hours;
  735. }
  736.  
  737. // check is current Overtime Hours is the new min and/or max
  738. if (emp_ptr->overtimeHrs < emp_minMax_ptr->min_overtimeHrs)
  739. {
  740. emp_minMax_ptr->min_overtimeHrs = emp_ptr->overtimeHrs;
  741. }
  742.  
  743. if (emp_ptr->overtimeHrs > emp_minMax_ptr->max_overtimeHrs)
  744. {
  745. emp_minMax_ptr->max_overtimeHrs = emp_ptr->overtimeHrs;
  746. }
  747.  
  748. // check is current Gross Pay is the new min and/or max
  749. if (emp_ptr->grossPay < emp_minMax_ptr->min_grossPay)
  750. {
  751. emp_minMax_ptr->min_grossPay = emp_ptr->grossPay;
  752. }
  753.  
  754. if (emp_ptr->grossPay > emp_minMax_ptr->max_grossPay)
  755. {
  756. emp_minMax_ptr->max_grossPay = emp_ptr->grossPay;
  757. }
  758.  
  759. // check is current State Tax is the new min and/or max
  760. if (emp_ptr->stateTax < emp_minMax_ptr->min_stateTax)
  761. {
  762. emp_minMax_ptr->min_stateTax = emp_ptr->stateTax;
  763. }
  764.  
  765. if (emp_ptr->stateTax > emp_minMax_ptr->max_stateTax)
  766. {
  767. emp_minMax_ptr->max_stateTax = emp_ptr->stateTax;
  768. }
  769.  
  770. // check is current Federal Tax is the new min and/or max
  771. if (emp_ptr->fedTax < emp_minMax_ptr->min_fedTax)
  772. {
  773. emp_minMax_ptr->min_fedTax = emp_ptr->fedTax;
  774. }
  775.  
  776. if (emp_ptr->fedTax > emp_minMax_ptr->max_fedTax)
  777. {
  778. emp_minMax_ptr->max_fedTax = emp_ptr->fedTax;
  779. }
  780.  
  781. // check is current Net Pay is the new min and/or max
  782. if (emp_ptr->netPay < emp_minMax_ptr->min_netPay)
  783. {
  784. emp_minMax_ptr->min_netPay = emp_ptr->netPay;
  785. }
  786.  
  787. if (emp_ptr->netPay > emp_minMax_ptr->max_netPay)
  788. {
  789. emp_minMax_ptr->max_netPay = emp_ptr->netPay;
  790. }
  791.  
  792. } // else if
  793.  
  794. } // 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