fork download
  1. //********************************************************
  2. //
  3. // Assignment 8 - Structures and Strings and Pointers
  4. //
  5. // Name: <Mario Morkus>
  6. //
  7. // Class: C Programming, <Spring 2026>
  8. //
  9. // Date: <04/05/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]; // employee first name
  52. char lastName [LAST_NAME_SIZE]; // employee last name
  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; // employee's first and last name
  62. char taxState [TAX_STATE_SIZE]; // 2-letter state where work is performed
  63. long int clockNumber; // unique employee clock/ID number
  64. float wageRate; // hourly wage rate
  65. float hours; // total hours worked in the week
  66. float overtimeHrs; // overtime hours beyond STD_HOURS
  67. float grossPay; // gross pay before taxes
  68. float stateTax; // state tax owed based on tax state
  69. float fedTax; // federal tax owed
  70. float netPay; // take-home pay after all taxes
  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; // sum of all employee wage rates
  78. float total_hours; // sum of all hours worked
  79. float total_overtimeHrs; // sum of all overtime hours
  80. float total_grossPay; // sum of all gross pay values
  81. float total_stateTax; // sum of all state taxes
  82. float total_fedTax; // sum of all federal taxes
  83. float total_netPay; // sum of all net pay values
  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; // minimum wage rate across all employees
  91. float min_hours; // minimum hours worked
  92. float min_overtimeHrs; // minimum overtime hours
  93. float min_grossPay; // minimum gross pay
  94. float min_stateTax; // minimum state tax
  95. float min_fedTax; // minimum federal tax
  96. float min_netPay; // minimum net pay
  97. float max_wageRate; // maximum wage rate across all employees
  98. float max_hours; // maximum hours worked
  99. float max_overtimeHrs; // maximum overtime hours
  100. float max_grossPay; // maximum gross pay
  101. float max_stateTax; // maximum state tax
  102. float max_fedTax; // maximum federal tax
  103. float max_netPay; // maximum net pay
  104. };
  105.  
  106. // define prototypes here for each function except main
  107. void getHours (struct employee * emp_ptr, int theSize);
  108. void calcOvertimeHrs (struct employee * emp_ptr, int theSize);
  109. void calcGrossPay (struct employee * emp_ptr, int theSize);
  110. void printHeader (void);
  111. void printEmp (struct employee * emp_ptr, int theSize);
  112. void calcStateTax (struct employee * emp_ptr, int theSize);
  113. void calcFedTax (struct employee * emp_ptr, int theSize);
  114. void calcNetPay (struct employee * emp_ptr, int theSize);
  115. void calcEmployeeTotals (struct employee * emp_ptr,
  116. struct totals * emp_totals_ptr,
  117. int theSize);
  118.  
  119. void calcEmployeeMinMax (struct employee * emp_ptr,
  120. struct min_max * emp_minMax_ptr,
  121. int theSize);
  122.  
  123. void printEmpStatistics (struct totals * emp_totals_ptr,
  124. struct min_max * emp_minMax_ptr,
  125. int theSize);
  126.  
  127.  
  128. int main ()
  129. {
  130.  
  131. // Set up a local variable to store the employee information
  132. // Initialize the name, tax state, clock number, and wage rate
  133. struct employee employeeData[SIZE] = {
  134. { {"Connie", "Cobol"}, "MA", 98401, 10.60},
  135. { {"Mary", "Apl"}, "NH", 526488, 9.75 },
  136. { {"Frank", "Fortran"}, "VT", 765349, 10.50 },
  137. { {"Jeff", "Ada"}, "NY", 34645, 12.25 },
  138. { {"Anton", "Pascal"},"CA",127615, 8.35 }
  139. };
  140.  
  141. // declare a pointer to the array of employee structures
  142. struct employee * emp_ptr;
  143.  
  144. // set the pointer to point to the array of employees
  145. emp_ptr = employeeData;
  146.  
  147. // set up structure to store totals and initialize all to zero
  148. struct totals employeeTotals = {0,0,0,0,0,0,0};
  149.  
  150. // pointer to the employeeTotals structure
  151. struct totals * emp_totals_ptr = &employeeTotals;
  152.  
  153. // set up structure to store min and max values and initialize all to zero
  154. struct min_max employeeMinMax = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  155.  
  156. // pointer to the employeeMinMax structure
  157. struct min_max * emp_minMax_ptr = &employeeMinMax;
  158.  
  159. // Call functions as needed to read and calculate information
  160.  
  161. // Prompt for the number of hours worked by the employee
  162. getHours (employeeData, SIZE);
  163.  
  164. // Calculate the overtime hours
  165. calcOvertimeHrs (employeeData, SIZE);
  166.  
  167. // Calculate the weekly gross pay
  168. calcGrossPay (employeeData, SIZE);
  169.  
  170. // Calculate the state tax
  171. calcStateTax (employeeData, SIZE);
  172.  
  173. // Calculate the federal tax
  174. calcFedTax (employeeData, SIZE);
  175.  
  176. // Calculate the net pay after taxes
  177. calcNetPay (employeeData, SIZE);
  178.  
  179. // Keep a running sum of the employee totals
  180. calcEmployeeTotals (employeeData,
  181. &employeeTotals,
  182. SIZE);
  183.  
  184. // Keep a running update of the employee minimum and maximum values
  185. calcEmployeeMinMax (employeeData,
  186. &employeeMinMax,
  187. SIZE);
  188. // Print the column headers
  189. printHeader();
  190.  
  191. // print out final information on each employee
  192. printEmp (employeeData, SIZE);
  193.  
  194. // print the totals and averages for all float items
  195. printEmpStatistics (&employeeTotals, &employeeMinMax, SIZE);
  196.  
  197. return (0); // success
  198.  
  199. } // main
  200.  
  201. //**************************************************************
  202. // Function: getHours
  203. //
  204. // Purpose: Obtains input from user, the number of hours worked
  205. // per employee and updates it in the array of structures
  206. // for each employee.
  207. //
  208. // Parameters:
  209. //
  210. // emp_ptr - pointer to array of employees (i.e., struct employee)
  211. // theSize - the array size (i.e., number of employees)
  212. //
  213. // Returns: void
  214. //
  215. //**************************************************************
  216.  
  217. void getHours (struct employee * emp_ptr, int theSize)
  218. {
  219.  
  220. int i; // loop index
  221.  
  222. // read in hours for each employee
  223. for (i = 0; i < theSize; ++i)
  224. {
  225. // Read in hours for employee
  226. printf("\nEnter hours worked by emp # %06li: ", emp_ptr->clockNumber);
  227. scanf ("%f", &emp_ptr->hours);
  228.  
  229. // set pointer to next employee
  230. ++emp_ptr;
  231. }
  232.  
  233. } // getHours
  234.  
  235. //**************************************************************
  236. // Function: printHeader
  237. //
  238. // Purpose: Prints the initial table header information.
  239. //
  240. // Parameters: none
  241. //
  242. // Returns: void
  243. //
  244. //**************************************************************
  245.  
  246. void printHeader (void)
  247. {
  248.  
  249. printf ("\n\n*** Pay Calculator ***\n");
  250.  
  251. // print the table header
  252. printf("\n--------------------------------------------------------------");
  253. printf("-------------------");
  254. printf("\nName Tax Clock# Wage Hours OT Gross ");
  255. printf(" State Fed Net");
  256. printf("\n State Pay ");
  257. printf(" Tax Tax Pay");
  258.  
  259. printf("\n--------------------------------------------------------------");
  260. printf("-------------------");
  261.  
  262. } // printHeader
  263.  
  264. //*************************************************************
  265. // Function: printEmp
  266. //
  267. // Purpose: Prints out all the information for each employee
  268. // in a nice and orderly table format.
  269. //
  270. // Parameters:
  271. //
  272. // emp_ptr - pointer to array of struct employee
  273. // theSize - the array size (i.e., number of employees)
  274. //
  275. // Returns: void
  276. //
  277. //**************************************************************
  278.  
  279. void printEmp (struct employee * emp_ptr, int theSize)
  280. {
  281.  
  282. int i; // array and loop index
  283.  
  284. // used to format the employee name
  285. char name [FIRST_NAME_SIZE + LAST_NAME_SIZE + 1];
  286.  
  287. // read in hours for each employee
  288. for (i = 0; i < theSize; ++i)
  289. {
  290. // While you could just print the first and last name in the printf
  291. // statement that follows, you could also use various C string library
  292. // functions to format the name exactly the way you want it. Breaking
  293. // the name into first and last members additionally gives you some
  294. // flexibility in printing. This also becomes more useful if we decide
  295. // later to store other parts of a person's name. I really did this just
  296. // to show you how to work with some of the common string functions.
  297. strcpy (name, emp_ptr->empName.firstName);
  298. strcat (name, " "); // add a space between first and last names
  299. strcat (name, emp_ptr->empName.lastName);
  300.  
  301. // Print out a single employee
  302. printf("\n%-20.20s %-2.2s %06li %5.2f %4.1f %4.1f %7.2f %6.2f %7.2f %8.2f",
  303. name, emp_ptr->taxState, emp_ptr->clockNumber,
  304. emp_ptr->wageRate, emp_ptr->hours,
  305. emp_ptr->overtimeHrs, emp_ptr->grossPay,
  306. emp_ptr->stateTax, emp_ptr->fedTax,
  307. emp_ptr->netPay);
  308.  
  309. // set pointer to next employee
  310. ++emp_ptr;
  311.  
  312. } // for
  313.  
  314. } // printEmp
  315.  
  316. //*************************************************************
  317. // Function: printEmpStatistics
  318. //
  319. // Purpose: Prints out the summary totals and averages of all
  320. // floating point value items for all employees
  321. // that have been processed. It also prints
  322. // out the min and max values.
  323. //
  324. // Parameters:
  325. //
  326. // emp_totals_ptr - a pointer to a structure containing a running total
  327. // of all employee floating point items
  328. // emp_minMax_ptr - a pointer to a structure containing all the minimum
  329. // and maximum values of all employee
  330. // floating point items
  331. // theSize - the total number of employees processed, used
  332. // to check for zero or negative divide condition.
  333. //
  334. // Returns: void
  335. //
  336. //**************************************************************
  337.  
  338. void printEmpStatistics (struct totals * emp_totals_ptr,
  339. struct min_max * emp_minMax_ptr,
  340. int theSize)
  341. {
  342.  
  343. // print a separator line
  344. printf("\n--------------------------------------------------------------");
  345. printf("-------------------");
  346.  
  347. // print the totals for all the floating point fields
  348. printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  349. emp_totals_ptr->total_wageRate,
  350. emp_totals_ptr->total_hours,
  351. emp_totals_ptr->total_overtimeHrs,
  352. emp_totals_ptr->total_grossPay,
  353. emp_totals_ptr->total_stateTax,
  354. emp_totals_ptr->total_fedTax,
  355. emp_totals_ptr->total_netPay);
  356.  
  357. // make sure you don't divide by zero or a negative number
  358. if (theSize > 0)
  359. {
  360. // print the averages for all the floating point fields
  361. printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  362. emp_totals_ptr->total_wageRate / theSize,
  363. emp_totals_ptr->total_hours / theSize,
  364. emp_totals_ptr->total_overtimeHrs / theSize,
  365. emp_totals_ptr->total_grossPay / theSize,
  366. emp_totals_ptr->total_stateTax / theSize,
  367. emp_totals_ptr->total_fedTax / theSize,
  368. emp_totals_ptr->total_netPay / theSize);
  369. } // if
  370.  
  371. // print the min and max values
  372. printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  373. emp_minMax_ptr->min_wageRate,
  374. emp_minMax_ptr->min_hours,
  375. emp_minMax_ptr->min_overtimeHrs,
  376. emp_minMax_ptr->min_grossPay,
  377. emp_minMax_ptr->min_stateTax,
  378. emp_minMax_ptr->min_fedTax,
  379. emp_minMax_ptr->min_netPay);
  380.  
  381. printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  382. emp_minMax_ptr->max_wageRate,
  383. emp_minMax_ptr->max_hours,
  384. emp_minMax_ptr->max_overtimeHrs,
  385. emp_minMax_ptr->max_grossPay,
  386. emp_minMax_ptr->max_stateTax,
  387. emp_minMax_ptr->max_fedTax,
  388. emp_minMax_ptr->max_netPay);
  389.  
  390. } // printEmpStatistics
  391.  
  392. //*************************************************************
  393. // Function: calcOvertimeHrs
  394. //
  395. // Purpose: Calculates the overtime hours worked by an employee
  396. // in a given week for each employee.
  397. //
  398. // Parameters:
  399. //
  400. // emp_ptr - pointer to array of employees (i.e., struct employee)
  401. // theSize - the array size (i.e., number of employees)
  402. //
  403. // Returns: void
  404. //
  405. //**************************************************************
  406.  
  407. void calcOvertimeHrs (struct employee * emp_ptr, int theSize)
  408. {
  409.  
  410. int i; // array and loop index
  411.  
  412. // calculate overtime hours for each employee
  413. for (i = 0; i < theSize; ++i)
  414. {
  415. // Any overtime ?
  416. if (emp_ptr->hours >= STD_HOURS)
  417. {
  418. emp_ptr->overtimeHrs = emp_ptr->hours - STD_HOURS;
  419. }
  420. else // no overtime
  421. {
  422. emp_ptr->overtimeHrs = 0;
  423. }
  424.  
  425. // set pointer to next employee
  426. ++emp_ptr;
  427.  
  428. } // for
  429.  
  430.  
  431. } // calcOvertimeHrs
  432.  
  433. //*************************************************************
  434. // Function: calcGrossPay
  435. //
  436. // Purpose: Calculates the gross pay based on the the normal pay
  437. // and any overtime pay for a given week for each
  438. // employee.
  439. //
  440. // Parameters:
  441. //
  442. // emp_ptr - pointer to array of employees (i.e., struct employee)
  443. // theSize - the array size (i.e., number of employees)
  444. //
  445. // Returns: void
  446. //
  447. //**************************************************************
  448.  
  449. void calcGrossPay (struct employee * emp_ptr, int theSize)
  450. {
  451. int i; // loop and array index
  452. float theNormalPay; // normal pay without any overtime hours
  453. float theOvertimePay; // overtime pay
  454.  
  455. // calculate grossPay for each employee
  456. for (i=0; i < theSize; ++i)
  457. {
  458. // calculate normal pay and any overtime pay
  459. theNormalPay = emp_ptr->wageRate *
  460. (emp_ptr->hours - emp_ptr->overtimeHrs);
  461. theOvertimePay = emp_ptr->overtimeHrs *
  462. (OT_RATE * emp_ptr->wageRate);
  463.  
  464. // calculate gross pay for employee as normalPay + any overtime pay
  465. emp_ptr->grossPay = theNormalPay + theOvertimePay;
  466.  
  467. // set pointer to next employee
  468. ++emp_ptr;
  469. }
  470.  
  471. } // calcGrossPay
  472.  
  473. //*************************************************************
  474. // Function: calcStateTax
  475. //
  476. // Purpose: Calculates the State Tax owed based on gross pay
  477. // for each employee. State tax rate is based on the
  478. // the designated tax state based on where the
  479. // employee is actually performing the work. Each
  480. // state decides their tax rate.
  481. //
  482. // Parameters:
  483. //
  484. // emp_ptr - pointer to array of employees (i.e., struct employee)
  485. // theSize - the array size (i.e., number of employees)
  486. //
  487. // Returns: void
  488. //
  489. //**************************************************************
  490.  
  491. void calcStateTax (struct employee * emp_ptr, int theSize)
  492. {
  493.  
  494. int i; // loop and array index
  495.  
  496. // calculate state tax based on where employee works
  497. for (i=0; i < theSize; ++i)
  498. {
  499. // Make sure tax state is all uppercase
  500. if (islower(emp_ptr->taxState[0]))
  501. emp_ptr->taxState[0] = toupper(emp_ptr->taxState[0]);
  502. if (islower(emp_ptr->taxState[1]))
  503. emp_ptr->taxState[1] = toupper(emp_ptr->taxState[1]);
  504.  
  505. // calculate state tax based on where employee resides
  506. if (strcmp(emp_ptr->taxState, "MA") == 0)
  507. emp_ptr->stateTax = emp_ptr->grossPay * MA_TAX_RATE;
  508. else if (strcmp(emp_ptr->taxState, "NH") == 0)
  509. emp_ptr->stateTax = emp_ptr->grossPay * NH_TAX_RATE;
  510. else if (strcmp(emp_ptr->taxState, "VT") == 0)
  511. // Vermont has a 6% state income tax rate
  512. emp_ptr->stateTax = emp_ptr->grossPay * VT_TAX_RATE;
  513. else if (strcmp(emp_ptr->taxState, "CA") == 0)
  514. // California has a 7% state income tax rate
  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. // set pointer to next employee
  521. ++emp_ptr;
  522. } // for
  523.  
  524. } // calcStateTax
  525.  
  526. //*************************************************************
  527. // Function: calcFedTax
  528. //
  529. // Purpose: Calculates the Federal Tax owed based on the gross
  530. // pay for each employee
  531. //
  532. // Parameters:
  533. //
  534. // emp_ptr - pointer to array of employees (i.e., struct employee)
  535. // theSize - the array size (i.e., number of employees)
  536. //
  537. // Returns: void
  538. //
  539. //**************************************************************
  540.  
  541. void calcFedTax (struct employee * emp_ptr, int theSize)
  542. {
  543.  
  544. int i; // loop and array index
  545.  
  546. // calculate the federal tax for each employee
  547. for (i=0; i < theSize; ++i)
  548. {
  549. // Fed Tax is the same for all regardless of state
  550. emp_ptr->fedTax = emp_ptr->grossPay * FED_TAX_RATE;
  551.  
  552. // set pointer to next employee
  553. ++emp_ptr;
  554.  
  555. } // for
  556.  
  557. } // calcFedTax
  558.  
  559. //*************************************************************
  560. // Function: calcNetPay
  561. //
  562. // Purpose: Calculates the net pay as the gross pay minus any
  563. // state and federal taxes owed for each employee.
  564. // Essentially, their "take home" pay.
  565. //
  566. // Parameters:
  567. //
  568. // emp_ptr - pointer to array of employees (i.e., struct employee)
  569. // theSize - the array size (i.e., number of employees)
  570. //
  571. // Returns: void
  572. //
  573. //**************************************************************
  574.  
  575. void calcNetPay (struct employee * emp_ptr, int theSize)
  576. {
  577. int i; // loop and array index
  578. float theTotalTaxes; // the total state and federal tax
  579.  
  580. // calculate the take home pay for each employee
  581. for (i=0; i < theSize; ++i)
  582. {
  583. // calculate the total state and federal taxes
  584. theTotalTaxes = emp_ptr->stateTax + emp_ptr->fedTax;
  585.  
  586. // calculate the net pay
  587. emp_ptr->netPay = emp_ptr->grossPay - theTotalTaxes;
  588.  
  589. // set pointer to next employee
  590. ++emp_ptr;
  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 (i.e., struct employee)
  605. // emp_totals_ptr - pointer to structure containing a running totals
  606. // of all fields above
  607. // theSize - the array size (i.e., number of employees)
  608. //
  609. // Returns: void
  610. //
  611. //**************************************************************
  612.  
  613. void calcEmployeeTotals (struct employee * emp_ptr,
  614. struct totals * emp_totals_ptr,
  615. int theSize)
  616. {
  617.  
  618. int i; // loop and array index
  619.  
  620. // total up each floating point item for all employees
  621. for (i = 0; i < theSize; ++i)
  622. {
  623. // add current employee data to our running totals
  624. emp_totals_ptr->total_wageRate += emp_ptr->wageRate;
  625. emp_totals_ptr->total_hours += emp_ptr->hours;
  626. emp_totals_ptr->total_overtimeHrs += emp_ptr->overtimeHrs;
  627. emp_totals_ptr->total_grossPay += emp_ptr->grossPay;
  628. emp_totals_ptr->total_stateTax += emp_ptr->stateTax;
  629. emp_totals_ptr->total_fedTax += emp_ptr->fedTax;
  630. emp_totals_ptr->total_netPay += emp_ptr->netPay;
  631.  
  632. // set pointer to next employee
  633. ++emp_ptr;
  634.  
  635. } // for
  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 employees (i.e., struct employee)
  649. // emp_minMax_ptr - pointer to structure containing min and max totals
  650. // of all fields above
  651. // theSize - the array size (i.e., number of employees)
  652. //
  653. // Returns: void
  654. //
  655. //**************************************************************
  656.  
  657. void calcEmployeeMinMax (struct employee * emp_ptr,
  658. struct min_max * emp_minMax_ptr,
  659. int theSize)
  660. {
  661.  
  662. int i; // array and loop index
  663.  
  664. // if this is the first set of data items, set
  665. // them to the min and max
  666. emp_minMax_ptr->min_wageRate = emp_ptr->wageRate;
  667. emp_minMax_ptr->min_hours = emp_ptr->hours;
  668. emp_minMax_ptr->min_overtimeHrs = emp_ptr->overtimeHrs;
  669. emp_minMax_ptr->min_grossPay = emp_ptr->grossPay;
  670. emp_minMax_ptr->min_stateTax = emp_ptr->stateTax;
  671. emp_minMax_ptr->min_fedTax = emp_ptr->fedTax;
  672. emp_minMax_ptr->min_netPay = emp_ptr->netPay;
  673.  
  674. // set the max to the first element members
  675. emp_minMax_ptr->max_wageRate = emp_ptr->wageRate;
  676. emp_minMax_ptr->max_hours = emp_ptr->hours;
  677. emp_minMax_ptr->max_overtimeHrs = emp_ptr->overtimeHrs;
  678. emp_minMax_ptr->max_grossPay = emp_ptr->grossPay;
  679. emp_minMax_ptr->max_stateTax = emp_ptr->stateTax;
  680. emp_minMax_ptr->max_fedTax = emp_ptr->fedTax;
  681. emp_minMax_ptr->max_netPay = emp_ptr->netPay;
  682.  
  683. // compare the rest of the items to each other for min and max
  684. for (i = 1; i < theSize; ++i)
  685. {
  686. // set pointer to next employee
  687. ++emp_ptr;
  688.  
  689. // check if current Wage Rate is the new min and/or max
  690. if (emp_ptr->wageRate < emp_minMax_ptr->min_wageRate)
  691. {
  692. emp_minMax_ptr->min_wageRate = emp_ptr->wageRate;
  693. }
  694.  
  695. if (emp_ptr->wageRate > emp_minMax_ptr->max_wageRate)
  696. {
  697. emp_minMax_ptr->max_wageRate = emp_ptr->wageRate;
  698. }
  699.  
  700. // check if current Hours is the new min and/or max
  701. if (emp_ptr->hours < emp_minMax_ptr->min_hours)
  702. {
  703. emp_minMax_ptr->min_hours = emp_ptr->hours;
  704. }
  705.  
  706. if (emp_ptr->hours > emp_minMax_ptr->max_hours)
  707. {
  708. emp_minMax_ptr->max_hours = emp_ptr->hours;
  709. }
  710.  
  711. // check if current Overtime Hours is the new min and/or max
  712. if (emp_ptr->overtimeHrs < emp_minMax_ptr->min_overtimeHrs)
  713. {
  714. emp_minMax_ptr->min_overtimeHrs = emp_ptr->overtimeHrs;
  715. }
  716.  
  717. if (emp_ptr->overtimeHrs > emp_minMax_ptr->max_overtimeHrs)
  718. {
  719. emp_minMax_ptr->max_overtimeHrs = emp_ptr->overtimeHrs;
  720. }
  721.  
  722. // check if current Gross Pay is the new min and/or max
  723. if (emp_ptr->grossPay < emp_minMax_ptr->min_grossPay)
  724. {
  725. emp_minMax_ptr->min_grossPay = emp_ptr->grossPay;
  726. }
  727.  
  728. if (emp_ptr->grossPay > emp_minMax_ptr->max_grossPay)
  729. {
  730. emp_minMax_ptr->max_grossPay = emp_ptr->grossPay;
  731. }
  732.  
  733. // check if current State Tax is the new min and/or max
  734. if (emp_ptr->stateTax < emp_minMax_ptr->min_stateTax)
  735. {
  736. emp_minMax_ptr->min_stateTax = emp_ptr->stateTax;
  737. }
  738.  
  739. if (emp_ptr->stateTax > emp_minMax_ptr->max_stateTax)
  740. {
  741. emp_minMax_ptr->max_stateTax = emp_ptr->stateTax;
  742. }
  743.  
  744. // check if current Federal Tax is the new min and/or max
  745. if (emp_ptr->fedTax < emp_minMax_ptr->min_fedTax)
  746. {
  747. emp_minMax_ptr->min_fedTax = emp_ptr->fedTax;
  748. }
  749.  
  750. if (emp_ptr->fedTax > emp_minMax_ptr->max_fedTax)
  751. {
  752. emp_minMax_ptr->max_fedTax = emp_ptr->fedTax;
  753. }
  754.  
  755. // check if current Net Pay is the new min and/or max
  756. if (emp_ptr->netPay < emp_minMax_ptr->min_netPay)
  757. {
  758. emp_minMax_ptr->min_netPay = emp_ptr->netPay;
  759. }
  760.  
  761. if (emp_ptr->netPay > emp_minMax_ptr->max_netPay)
  762. {
  763. emp_minMax_ptr->max_netPay = emp_ptr->netPay;
  764. }
  765.  
  766. } // else if
  767.  
  768. } // calcEmployeeMinMax
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