fork download
  1. //********************************************************
  2. //
  3. // Assignment 7 - Structures and Strings
  4. //
  5. // Name: <Maribel Fuentes>
  6. //
  7. // Class: C Programming, <Fall 2024 Semester>
  8. //
  9. // Date: <October 29, 2024>
  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. 0.0,
  333. 0.0,
  334. 0.0,
  335. 0.0,
  336. 0.0,
  337. 0.0);
  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. 0.0,
  348. 0.0,
  349. 0.0,
  350. 0.0,
  351. 0.0,
  352. 0.0);
  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. 0.0,
  361. 0.0,
  362. 0.0,
  363. 0.0,
  364. 0.0,
  365. 0.0);
  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. 0.0,
  372. 0.0,
  373. 0.0,
  374. 0.0,
  375. 0.0,
  376. 0.0);
  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 = 0;
  497. else if (strcmp(employeeData[i].taxState, "CA") == 0)
  498. employeeData[i].stateTax = 0;
  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. int i; // loop and array index
  523.  
  524. // calculate the federal tax for each employee
  525. for (i = 0; i < theSize; ++i) {
  526. // Fed Tax is the same for all regardless of state
  527. employeeData[i].fedTax = employeeData[i].grossPay * FED_TAX_RATE;
  528. } // for
  529. } // calcFedTax
  530.  
  531. //*************************************************************
  532. // Function: calcNetPay
  533. //
  534. // Purpose: Calculates the net pay as the gross pay minus any
  535. // state and federal taxes owed for each employee.
  536. // Essentially, their "take home" pay.
  537. //
  538. // Parameters:
  539. //
  540. // employeeData - array of employees (i.e., struct employee)
  541. // theSize - the array size (i.e., number of employees)
  542. //
  543. // Returns: void
  544. //
  545. //**************************************************************
  546.  
  547. void calcNetPay(struct employee employeeData[], int theSize) {
  548. int i; // loop and array index
  549. float theTotalTaxes; // the total state and federal tax
  550.  
  551. // calculate the take home pay for each employee
  552. for (i = 0; i < theSize; ++i) {
  553. // calculate the total state and federal taxes
  554. theTotalTaxes = employeeData[i].stateTax + employeeData[i].fedTax;
  555.  
  556. // calculate the net pay
  557. employeeData[i].netPay = employeeData[i].grossPay - theTotalTaxes;
  558. } // for
  559. } // calcNetPay
  560.  
  561. //*************************************************************
  562. // Function: calcEmployeeTotals
  563. //
  564. // Purpose: Performs a running total (sum) of each employee
  565. // floating point member in the array of structures
  566. //
  567. // Parameters:
  568. //
  569. // employeeData - array of employees (i.e., struct employee)
  570. // employeeTotals - structure containing a running totals
  571. // of all fields above
  572. // theSize - the array size (i.e., number of employees)
  573. //
  574. // Returns: employeeTotals - updated totals in the updated
  575. // employeeTotals structure
  576. //
  577. //**************************************************************
  578.  
  579. struct totals calcEmployeeTotals(struct employee employeeData[], struct totals employeeTotals, int theSize) {
  580. int i; // loop and array index
  581.  
  582. // total up each floating point item for all employees
  583. for (i = 0; i < theSize; ++i) {
  584. // add current employee data to our running totals
  585. employeeTotals.total_wageRate += employeeData[i].wageRate;
  586. employeeTotals.total_hours += employeeData[i].hours;
  587. employeeTotals.total_overtimeHrs += employeeData[i].overtimeHrs;
  588. employeeTotals.total_grossPay += employeeData[i].grossPay;
  589. employeeTotals.total_stateTax += employeeData[i].stateTax;
  590. employeeTotals.total_fedTax += employeeData[i].fedTax;
  591. employeeTotals.total_netPay += employeeData[i].netPay;
  592. } // for
  593.  
  594. return employeeTotals;
  595. } // calcEmployeeTotals
  596.  
  597. //*************************************************************
  598. // Function: calcEmployeeMinMax
  599. //
  600. // Purpose: Accepts various floating point values from an
  601. // employee and adds to a running update of min
  602. // and max values
  603. //
  604. // Parameters:
  605. //
  606. // employeeData - array of employees (i.e., struct employee)
  607. // employeeTotals - structure containing a running totals
  608. // of all fields above
  609. // theSize - the array size (i.e., number of employees)
  610. //
  611. // Returns: employeeMinMax - updated employeeMinMax structure
  612. //
  613. //**************************************************************
  614.  
  615. struct min_max calcEmployeeMinMax(struct employee employeeData[], struct min_max employeeMinMax, int theSize) {
  616. int i; // array and loop index
  617.  
  618. // if this is the first set of data items, set them to the min and max
  619. employeeMinMax.min_wageRate = employeeData[0].wageRate;
  620. employeeMinMax.min_hours = employeeData[0].hours;
  621. employeeMinMax.min_overtimeHrs = employeeData[0].overtimeHrs;
  622. employeeMinMax.min_grossPay = employeeData[0].grossPay;
  623. employeeMinMax.min_stateTax = employeeData[0].stateTax;
  624. employeeMinMax.min_fedTax = employeeData[0].fedTax;
  625. employeeMinMax.min_netPay = employeeData[0].netPay;
  626.  
  627. // set the max to the first element members
  628. employeeMinMax.max_wageRate = employeeData[0].wageRate;
  629. employeeMinMax.max_hours = employeeData[0].hours;
  630. employeeMinMax.max_overtimeHrs = employeeData[0].overtimeHrs;
  631. employeeMinMax.max_grossPay = employeeData[0].grossPay;
  632. employeeMinMax.max_stateTax = employeeData[0].stateTax;
  633. employeeMinMax.max_fedTax = employeeData[0].fedTax;
  634. employeeMinMax.max_netPay = employeeData[0].netPay;
  635.  
  636. // compare the rest of the items to each other for min and max
  637. for (i = 1; i < theSize; ++i) {
  638. // check if current Wage Rate is the new min and/or max
  639. if (employeeData[i].wageRate < employeeMinMax.min_wageRate) {
  640. employeeMinMax.min_wageRate = employeeData[i].wageRate;
  641. }
  642.  
  643. if (employeeData[i].wageRate > employeeMinMax.max_wageRate) {
  644. employeeMinMax.max_wageRate = employeeData[i].wageRate;
  645. }
  646.  
  647. // check if current Hours is the new min and/or max
  648. if (employeeData[i].hours < employeeMinMax.min_hours) {
  649. employeeMinMax.min_hours = employeeData[i].hours;
  650. }
  651.  
  652. if (employeeData[i].hours > employeeMinMax.max_hours) {
  653. employeeMinMax.max_hours = employeeData[i].hours;
  654. }
  655.  
  656. // check if current Overtime Hours is the new min and/or max
  657. if (employeeData[i].overtimeHrs < employeeMinMax.min_overtimeHrs) {
  658. employeeMinMax.min_overtimeHrs = employeeData[i].overtimeHrs;
  659. }
  660.  
  661. if (employeeData[i].overtimeHrs > employeeMinMax.max_overtimeHrs) {
  662. employeeMinMax.max_overtimeHrs = employeeData[i].overtimeHrs;
  663. }
  664.  
  665. // check if current Gross Pay is the new min and/or max
  666. if (employeeData[i].grossPay < employeeMinMax.min_grossPay) {
  667. employeeMinMax.min_grossPay = employeeData[i].grossPay;
  668. }
  669.  
  670. if (employeeData[i].grossPay > employeeMinMax.max_grossPay) {
  671. employeeMinMax.max_grossPay = employeeData[i].grossPay;
  672. }
  673.  
  674. // check if current State Tax is the new min and/or max
  675. if (employeeData[i].stateTax < employeeMinMax.min_stateTax) {
  676. employeeMinMax.min_stateTax = employeeData[i].stateTax;
  677. }
  678.  
  679. if (employeeData[i].stateTax > employeeMinMax.max_stateTax) {
  680. employeeMinMax.max_stateTax = employeeData[i].stateTax;
  681. }
  682.  
  683. // check if current Federal Tax is the new min and/or max
  684. if (employeeData[i].fedTax < employeeMinMax.min_fedTax) {
  685. employeeMinMax.min_fedTax = employeeData[i].fedTax;
  686. }
  687.  
  688. if (employeeData[i].fedTax > employeeMinMax.max_fedTax) {
  689. employeeMinMax.max_fedTax = employeeData[i].fedTax;
  690. }
  691.  
  692. // check if current Net Pay is the new min and/or max
  693. if (employeeData[i].netPay < employeeMinMax.min_netPay) {
  694. employeeMinMax.min_netPay = employeeData[i].netPay;
  695. }
  696.  
  697. if (employeeData[i].netPay > employeeMinMax.max_netPay) {
  698. employeeMinMax.max_netPay = employeeData[i].netPay;
  699. }
  700. } // for
  701.  
  702. // return all the updated min and max values to the calling function
  703. return employeeMinMax;
  704. } // calcEmployeeMinMax
Success #stdin #stdout 0.01s 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   0.00   97.12   291.38
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   0.00   83.50   250.50
---------------------------------------------------------------------------------
Totals:                         51.45   0.0   0.0    0.00   0.00    0.00     0.00
Averages:                       10.29   0.0   0.0    0.00   0.00    0.00     0.00
Minimum:                         8.35   0.0   0.0    0.00   0.00    0.00     0.00
Maximum:                        12.25   0.0   0.0    0.00   0.00    0.00     0.00