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