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