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