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