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