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