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