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