fork download
  1. //********************************************************
  2. //
  3. // Assignment 7 - Structures and Strings
  4. //
  5. // Name: Po Yuen
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: March 25, 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> // standard input/output for printf and scanf
  25. #include <string.h> // string functions like strcpy, strcat, strcmp
  26. #include <ctype.h> // character functions like toupper, islower
  27. // define constants
  28. #define SIZE 5 // number of employees to process
  29. #define STD_HOURS 40.0 // standard weekly hours before overtime
  30. #define OT_RATE 1.5 // overtime pay multiplier (time and a half)
  31. #define MA_TAX_RATE 0.05 // Massachusetts state tax rate (5%)
  32. #define NH_TAX_RATE 0.0 // New Hampshire state tax rate (0%)
  33. #define VT_TAX_RATE 0.06 // Vermont state tax rate (6%)
  34. #define CA_TAX_RATE 0.07 // California state tax rate (7%)
  35. #define DEFAULT_TAX_RATE 0.08 // default state tax rate for all others (8%)
  36. #define NAME_SIZE 20 // max size for a full formatted name
  37. #define TAX_STATE_SIZE 3 // size for two-char state code plus null
  38. #define FED_TAX_RATE 0.25 // federal tax rate for all employees (25%)
  39. #define FIRST_NAME_SIZE 10 // max size for employee first name
  40. #define LAST_NAME_SIZE 10 // max size for employee last name
  41. // Define a structure type to store an employee name
  42. // ... note how one could easily extend this to other parts
  43. // parts of a name: Middle, Nickname, Prefix, Suffix, etc.
  44. struct name
  45. {
  46. char firstName[FIRST_NAME_SIZE]; // employee first name
  47. char lastName [LAST_NAME_SIZE]; // employee last name
  48. };
  49. // Define a structure type to pass employee data between functions
  50. // Note that the structure type is global, but you don't want a variable
  51. // of that type to be global. Best to declare a variable of that type
  52. // in a function like main or another function and pass as needed.
  53. struct employee
  54. {
  55. struct name empName; // employee name (first and last)
  56. char taxState [TAX_STATE_SIZE]; // two-character state tax code
  57. long int clockNumber; // unique employee clock number
  58. float wageRate; // hourly wage rate
  59. float hours; // total hours worked this week
  60. float overtimeHrs; // overtime hours beyond standard
  61. float grossPay; // total gross pay before taxes
  62. float stateTax; // calculated state tax amount
  63. float fedTax; // calculated federal tax amount
  64. float netPay; // take home pay after all taxes
  65. };
  66. // this structure type defines the totals of all floating point items
  67. // so they can be totaled and used also to calculate averages
  68. struct totals
  69. {
  70. float total_wageRate; // running total of all wage rates
  71. float total_hours; // running total of all hours worked
  72. float total_overtimeHrs; // running total of all overtime hours
  73. float total_grossPay; // running total of all gross pay
  74. float total_stateTax; // running total of all state taxes
  75. float total_fedTax; // running total of all federal taxes
  76. float total_netPay; // running total of all net pay
  77. };
  78. // this structure type defines the min and max values of all floating
  79. // point items so they can be displayed in our final report
  80. struct min_max
  81. {
  82. float min_wageRate; // minimum wage rate across all employees
  83. float min_hours; // minimum hours worked across all employees
  84. float min_overtimeHrs; // minimum overtime hours across all employees
  85. float min_grossPay; // minimum gross pay across all employees
  86. float min_stateTax; // minimum state tax across all employees
  87. float min_fedTax; // minimum federal tax across all employees
  88. float min_netPay; // minimum net pay across all employees
  89. float max_wageRate; // maximum wage rate across all employees
  90. float max_hours; // maximum hours worked across all employees
  91. float max_overtimeHrs; // maximum overtime hours across all employees
  92. float max_grossPay; // maximum gross pay across all employees
  93. float max_stateTax; // maximum state tax across all employees
  94. float max_fedTax; // maximum federal tax across all employees
  95. float max_netPay; // maximum net pay across all employees
  96. };
  97. // define prototypes here for each function except main
  98. void getHours (struct employee employeeData[], int theSize);
  99. void calcOvertimeHrs (struct employee employeeData[], int theSize);
  100. void calcGrossPay (struct employee employeeData[], int theSize);
  101. void printHeader (void);
  102. void printEmp (struct employee employeeData[], int theSize);
  103. void calcStateTax (struct employee employeeData[], int theSize);
  104. void calcFedTax (struct employee employeeData[], int theSize);
  105. void calcNetPay (struct employee employeeData[], int theSize);
  106. struct totals calcEmployeeTotals (struct employee employeeData[],
  107. struct totals employeeTotals,
  108. int theSize);
  109.  
  110. struct min_max calcEmployeeMinMax (struct employee employeeData[],
  111. struct min_max employeeMinMax,
  112. int theSize);
  113.  
  114. void printEmpStatistics (struct totals employeeTotals,
  115. struct min_max employeeMinMax,
  116. int theSize);
  117. //**************************************************************
  118. // Function: main
  119. //
  120. // Purpose: Entry point of the program. Sets up the array of
  121. // employee structures with initial data, calls all
  122. // processing and output functions in the correct order,
  123. // and returns a success status.
  124. //
  125. // Parameters: none
  126. //
  127. // Returns: int - 0 for success
  128. //
  129. //**************************************************************
  130. int main ()
  131. {
  132.  
  133. // Set up a local variable to store the employee information
  134. // Initialize the name, tax state, clock number, and wage rate
  135. struct employee employeeData[SIZE] = {
  136. { {"Connie", "Cobol"}, "MA", 98401, 10.60},
  137. { {"Mary", "Apl"}, "NH", 526488, 9.75 },
  138. { {"Frank", "Fortran"}, "VT", 765349, 10.50 },
  139. { {"Jeff", "Ada"}, "NY", 34645, 12.25 },
  140. { {"Anton", "Pascal"},"CA",127615, 8.35 }
  141. };
  142.  
  143. // set up structure to store totals and initialize all to zero
  144. struct totals employeeTotals = {0,0,0,0,0,0,0};
  145.  
  146. // set up structure to store min and max values and initialize all to zero
  147. struct min_max employeeMinMax = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  148. // Call functions as needed to read and calculate information
  149. // Prompt for the number of hours worked by each employee
  150. getHours (employeeData, SIZE);
  151. // Calculate the overtime hours for each employee
  152. calcOvertimeHrs (employeeData, SIZE);
  153.  
  154. // Calculate the weekly gross pay for each employee
  155. calcGrossPay (employeeData, SIZE);
  156. // Calculate the state tax for each employee
  157. calcStateTax (employeeData, SIZE);
  158. // Calculate the federal tax for each employee
  159. calcFedTax (employeeData, SIZE);
  160.  
  161. // Calculate the net pay after taxes for each employee
  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. // Print out final information on each employee
  176. printEmp (employeeData, SIZE);
  177.  
  178. // Print the totals, averages, min, and max for all float items
  179. printEmpStatistics (employeeTotals, employeeMinMax, SIZE);
  180. return (0); // success
  181. } // main
  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. // loop through each employee to read in their hours
  201. for (i = 0; i < theSize; ++i)
  202. {
  203. // Prompt user and read in hours for the current employee
  204. printf("\nEnter hours worked by emp # %06li: ", employeeData[i].clockNumber);
  205. scanf ("%f", &employeeData[i].hours);
  206. } // for
  207.  
  208. } // getHours
  209. //**************************************************************
  210. // Function: printHeader
  211. //
  212. // Purpose: Prints the initial table header information including
  213. // the report title and column headings for all employee
  214. // data items.
  215. //
  216. // Parameters: none
  217. //
  218. // Returns: void
  219. //
  220. //**************************************************************
  221. void printHeader (void)
  222. {
  223. // print the report title
  224. printf ("\n\n*** Pay Calculator ***\n");
  225. // print the top separator line
  226. printf("\n--------------------------------------------------------------");
  227. printf("-------------------");
  228. // print the first row of column headers
  229. printf("\nName Tax Clock# Wage Hours OT Gross ");
  230. printf(" State Fed Net");
  231. // print the second row of column headers (sub-headers)
  232. printf("\n State Pay ");
  233. printf(" Tax Tax Pay");
  234.  
  235. // print the bottom separator line under the header
  236. printf("\n--------------------------------------------------------------");
  237. printf("-------------------");
  238. } // printHeader
  239. //*************************************************************
  240. // Function: printEmp
  241. //
  242. // Purpose: Prints out all the information for each employee
  243. // in a nice and orderly table format.
  244. //
  245. // Parameters:
  246. //
  247. // employeeData - array of struct employee
  248. // theSize - the array size (i.e., number of employees)
  249. //
  250. // Returns: void
  251. //
  252. //**************************************************************
  253. void printEmp (struct employee employeeData[], int theSize)
  254. {
  255.  
  256. int i; // array and loop index
  257.  
  258. // buffer to hold the formatted full name (first + space + last)
  259. char name [FIRST_NAME_SIZE + LAST_NAME_SIZE + 1];
  260. // loop through each employee and print their data
  261. for (i = 0; i < theSize; ++i)
  262. {
  263. // Build the full name string by copying first name into buffer
  264. strcpy (name, employeeData[i].empName.firstName);
  265. // Append a space between first and last names
  266. strcat (name, " ");
  267. // Append the last name to complete the full name
  268. strcat (name, employeeData[i].empName.lastName);
  269.  
  270. // Print out a single employee row with all data items formatted
  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.  
  278. } // for
  279.  
  280. } // printEmp
  281. //*************************************************************
  282. // Function: printEmpStatistics
  283. //
  284. // Purpose: Prints out the summary totals and averages of all
  285. // floating point value items for all employees
  286. // that have been processed. It also prints
  287. // out the min and max values.
  288. //
  289. // Parameters:
  290. //
  291. // employeeTotals - a structure containing a running total
  292. // of all employee floating point items
  293. // employeeMinMax - a structure containing all the minimum
  294. // and maximum values of all employee
  295. // floating point items
  296. // theSize - the total number of employees processed, used
  297. // to check for zero or negative divide condition.
  298. //
  299. // Returns: void
  300. //
  301. //**************************************************************
  302. void printEmpStatistics (struct totals employeeTotals,
  303. struct min_max employeeMinMax,
  304. int theSize)
  305. {
  306.  
  307. // print a separator line to mark the end of employee rows
  308. printf("\n--------------------------------------------------------------");
  309. printf("-------------------");
  310.  
  311. // print the totals row for all floating point fields
  312. printf("\nTotals: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  313. employeeTotals.total_wageRate,
  314. employeeTotals.total_hours,
  315. employeeTotals.total_overtimeHrs,
  316. employeeTotals.total_grossPay,
  317. employeeTotals.total_stateTax,
  318. employeeTotals.total_fedTax,
  319. employeeTotals.total_netPay);
  320.  
  321. // make sure you don't divide by zero or a negative number
  322. if (theSize > 0)
  323. {
  324. // print the averages row by dividing each total by the number of employees
  325. printf("\nAverages: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  326. employeeTotals.total_wageRate / theSize,
  327. employeeTotals.total_hours / theSize,
  328. employeeTotals.total_overtimeHrs / theSize,
  329. employeeTotals.total_grossPay / theSize,
  330. employeeTotals.total_stateTax / theSize,
  331. employeeTotals.total_fedTax / theSize,
  332. employeeTotals.total_netPay / theSize);
  333. } // if
  334.  
  335. // print the minimum values row for all floating point fields
  336. printf("\nMinimum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  337. employeeMinMax.min_wageRate,
  338. employeeMinMax.min_hours,
  339. employeeMinMax.min_overtimeHrs,
  340. employeeMinMax.min_grossPay,
  341. employeeMinMax.min_stateTax,
  342. employeeMinMax.min_fedTax,
  343. employeeMinMax.min_netPay);
  344.  
  345. // print the maximum values row for all floating point fields
  346. printf("\nMaximum: %5.2f %5.1f %5.1f %7.2f %6.2f %7.2f %8.2f",
  347. employeeMinMax.max_wageRate,
  348. employeeMinMax.max_hours,
  349. employeeMinMax.max_overtimeHrs,
  350. employeeMinMax.max_grossPay,
  351. employeeMinMax.max_stateTax,
  352. employeeMinMax.max_fedTax,
  353. employeeMinMax.max_netPay);
  354. } // printEmpStatistics
  355. //*************************************************************
  356. // Function: calcOvertimeHrs
  357. //
  358. // Purpose: Calculates the overtime hours worked by an employee
  359. // in a given week for each employee. Any hours over
  360. // the standard 40 hours are considered overtime.
  361. //
  362. // Parameters:
  363. //
  364. // employeeData - array of employees (i.e., struct employee)
  365. // theSize - the array size (i.e., number of employees)
  366. //
  367. // Returns: void
  368. //
  369. //**************************************************************
  370. void calcOvertimeHrs (struct employee employeeData[], int theSize)
  371. {
  372.  
  373. int i; // array and loop index
  374. // loop through each employee to calculate their overtime hours
  375. for (i = 0; i < theSize; ++i)
  376. {
  377. // Determine if the employee worked more than standard hours
  378. if (employeeData[i].hours >= STD_HOURS)
  379. {
  380. // overtime is total hours minus the standard hours
  381. employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS;
  382. }
  383. else // no overtime worked this week
  384. {
  385. // set overtime hours to zero
  386. employeeData[i].overtimeHrs = 0;
  387. }
  388.  
  389. } // for
  390. } // calcOvertimeHrs
  391. //*************************************************************
  392. // Function: calcGrossPay
  393. //
  394. // Purpose: Calculates the gross pay based on the normal pay
  395. // and any overtime pay for a given week for each
  396. // employee. Overtime is paid at 1.5 times the
  397. // normal wage rate.
  398. //
  399. // Parameters:
  400. //
  401. // employeeData - array of employees (i.e., struct employee)
  402. // theSize - the array size (i.e., number of employees)
  403. //
  404. // Returns: void
  405. //
  406. //**************************************************************
  407. void calcGrossPay (struct employee employeeData[], int theSize)
  408. {
  409. int i; // loop and array index
  410. float theNormalPay; // normal pay for hours at regular rate
  411. float theOvertimePay; // additional pay for overtime hours
  412. // loop through each employee to calculate their gross pay
  413. for (i=0; i < theSize; ++i)
  414. {
  415. // calculate normal pay: wage rate times regular (non-overtime) hours
  416. theNormalPay = employeeData[i].wageRate *
  417. (employeeData[i].hours - employeeData[i].overtimeHrs);
  418. // calculate overtime pay: OT hours times 1.5 times the wage rate
  419. theOvertimePay = employeeData[i].overtimeHrs *
  420. (OT_RATE * employeeData[i].wageRate);
  421.  
  422. // gross pay is the sum of normal pay and any overtime pay
  423. employeeData[i].grossPay = theNormalPay + theOvertimePay;
  424. } // for
  425. } // calcGrossPay
  426. //*************************************************************
  427. // Function: calcStateTax
  428. //
  429. // Purpose: Calculates the State Tax owed based on gross pay
  430. // for each employee. State tax rate is based on the
  431. // the designated tax state based on where the
  432. // employee is actually performing the work. Each
  433. // state decides their tax rate:
  434. // MA = 5%, NH = 0%, VT = 6%, CA = 7%
  435. // All other states = 8% (default)
  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
  443. //
  444. //**************************************************************
  445. void calcStateTax (struct employee employeeData[], int theSize)
  446. {
  447.  
  448. int i; // loop and array index
  449.  
  450. // loop through each employee to calculate their state tax
  451. for (i=0; i < theSize; ++i)
  452. {
  453. // Ensure the first character of taxState is uppercase
  454. if (islower(employeeData[i].taxState[0]))
  455. employeeData[i].taxState[0] = toupper(employeeData[i].taxState[0]);
  456. // Ensure the second character of taxState is uppercase
  457. if (islower(employeeData[i].taxState[1]))
  458. employeeData[i].taxState[1] = toupper(employeeData[i].taxState[1]);
  459.  
  460. // Determine the tax rate based on the employee's tax state
  461. if (strcmp(employeeData[i].taxState, "MA") == 0)
  462. {
  463. // Massachusetts tax: 5% of gross pay
  464. employeeData[i].stateTax = employeeData[i].grossPay * MA_TAX_RATE;
  465. }
  466. else if (strcmp(employeeData[i].taxState, "NH") == 0)
  467. {
  468. // New Hampshire tax: 0% of gross pay (no state income tax)
  469. employeeData[i].stateTax = employeeData[i].grossPay * NH_TAX_RATE;
  470. }
  471. else if (strcmp(employeeData[i].taxState, "VT") == 0)
  472. {
  473. // Vermont tax: 6% of gross pay
  474. employeeData[i].stateTax = employeeData[i].grossPay * VT_TAX_RATE;
  475. }
  476. else if (strcmp(employeeData[i].taxState, "CA") == 0)
  477. {
  478. // California tax: 7% of gross pay
  479. employeeData[i].stateTax = employeeData[i].grossPay * CA_TAX_RATE;
  480. }
  481. else
  482. {
  483. // All other states use the default tax rate of 8%
  484. employeeData[i].stateTax = employeeData[i].grossPay * DEFAULT_TAX_RATE;
  485. }
  486. } // for
  487.  
  488. } // calcStateTax
  489. //*************************************************************
  490. // Function: calcFedTax
  491. //
  492. // Purpose: Calculates the Federal Tax owed based on the gross
  493. // pay for each employee. All employees pay a flat
  494. // federal tax rate of 25% regardless of their state.
  495. //
  496. // Parameters:
  497. //
  498. // employeeData - array of employees (i.e., struct employee)
  499. // theSize - the array size (i.e., number of employees)
  500. //
  501. // Returns: void
  502. //
  503. //**************************************************************
  504. void calcFedTax (struct employee employeeData[], int theSize)
  505. {
  506.  
  507. int i; // loop and array index
  508.  
  509. // loop through each employee to calculate their federal tax
  510. for (i=0; i < theSize; ++i)
  511. {
  512. // Federal tax is a flat 25% of gross pay for all employees
  513. employeeData[i].fedTax = employeeData[i].grossPay * FED_TAX_RATE;
  514.  
  515. } // for
  516.  
  517. } // calcFedTax
  518. //*************************************************************
  519. // Function: calcNetPay
  520. //
  521. // Purpose: Calculates the net pay as the gross pay minus any
  522. // state and federal taxes owed for each employee.
  523. // Essentially, their "take home" pay.
  524. //
  525. // Parameters:
  526. //
  527. // employeeData - array of employees (i.e., struct employee)
  528. // theSize - the array size (i.e., number of employees)
  529. //
  530. // Returns: void
  531. //
  532. //**************************************************************
  533. void calcNetPay (struct employee employeeData[], int theSize)
  534. {
  535. int i; // loop and array index
  536. float theTotalTaxes; // the combined total of state and federal tax
  537.  
  538. // loop through each employee to calculate their take home pay
  539. for (i=0; i < theSize; ++i)
  540. {
  541. // sum up the state and federal taxes for this employee
  542. theTotalTaxes = employeeData[i].stateTax + employeeData[i].fedTax;
  543.  
  544. // net pay is gross pay minus the total taxes paid
  545. employeeData[i].netPay = employeeData[i].grossPay - theTotalTaxes;
  546. } // for
  547.  
  548. } // calcNetPay
  549. //*************************************************************
  550. // Function: calcEmployeeTotals
  551. //
  552. // Purpose: Performs a running total (sum) of each employee
  553. // floating point member in the array of structures.
  554. // These totals are used for the Totals and Averages
  555. // rows in the summary report.
  556. //
  557. // Parameters:
  558. //
  559. // employeeData - array of employees (i.e., struct employee)
  560. // employeeTotals - structure containing a running totals
  561. // of all fields above
  562. // theSize - the array size (i.e., number of employees)
  563. //
  564. // Returns: employeeTotals - updated totals in the updated
  565. // employeeTotals structure
  566. //
  567. //**************************************************************
  568. struct totals calcEmployeeTotals (struct employee employeeData[],
  569. struct totals employeeTotals,
  570. int theSize)
  571. {
  572.  
  573. int i; // loop and array index
  574.  
  575. // loop through each employee and accumulate running totals
  576. for (i = 0; i < theSize; ++i)
  577. {
  578. // add the current employee's wage rate to the running total
  579. employeeTotals.total_wageRate += employeeData[i].wageRate;
  580. // add the current employee's hours worked to the running total
  581. employeeTotals.total_hours += employeeData[i].hours;
  582. // add the current employee's overtime hours to the running total
  583. employeeTotals.total_overtimeHrs += employeeData[i].overtimeHrs;
  584. // add the current employee's gross pay to the running total
  585. employeeTotals.total_grossPay += employeeData[i].grossPay;
  586. // add the current employee's state tax to the running total
  587. employeeTotals.total_stateTax += employeeData[i].stateTax;
  588. // add the current employee's federal tax to the running total
  589. employeeTotals.total_fedTax += employeeData[i].fedTax;
  590. // add the current employee's net pay to the running total
  591. employeeTotals.total_netPay += employeeData[i].netPay;
  592.  
  593. } // for
  594.  
  595. // return the updated totals structure back to the caller
  596. return (employeeTotals);
  597.  
  598. } // calcEmployeeTotals
  599. //*************************************************************
  600. // Function: calcEmployeeMinMax
  601. //
  602. // Purpose: Determines the minimum and maximum values for each
  603. // floating point data item across all employees.
  604. // Initializes min and max to the first employee's
  605. // values, then compares the remaining employees.
  606. //
  607. // Parameters:
  608. //
  609. // employeeData - array of employees (i.e., struct employee)
  610. // employeeMinMax - structure containing the current min and
  611. // max values for all floating point fields
  612. // theSize - the array size (i.e., number of employees)
  613. //
  614. // Returns: employeeMinMax - updated employeeMinMax structure
  615. //
  616. //**************************************************************
  617. struct min_max calcEmployeeMinMax (struct employee employeeData[],
  618. struct min_max employeeMinMax,
  619. int theSize)
  620. {
  621. int i; // array and loop index
  622.  
  623. // Initialize all min values to the first employee's data
  624. employeeMinMax.min_wageRate = employeeData[0].wageRate;
  625. employeeMinMax.min_hours = employeeData[0].hours;
  626. employeeMinMax.min_overtimeHrs = employeeData[0].overtimeHrs;
  627. employeeMinMax.min_grossPay = employeeData[0].grossPay;
  628. employeeMinMax.min_stateTax = employeeData[0].stateTax;
  629. employeeMinMax.min_fedTax = employeeData[0].fedTax;
  630. employeeMinMax.min_netPay = employeeData[0].netPay;
  631.  
  632. // Initialize all max values to the first employee's data
  633. employeeMinMax.max_wageRate = employeeData[0].wageRate;
  634. employeeMinMax.max_hours = employeeData[0].hours;
  635. employeeMinMax.max_overtimeHrs = employeeData[0].overtimeHrs;
  636. employeeMinMax.max_grossPay = employeeData[0].grossPay;
  637. employeeMinMax.max_stateTax = employeeData[0].stateTax;
  638. employeeMinMax.max_fedTax = employeeData[0].fedTax;
  639. employeeMinMax.max_netPay = employeeData[0].netPay;
  640.  
  641. // Loop through remaining employees (starting at index 1) and
  642. // compare each data item to find the overall min and max
  643. for (i = 1; i < theSize; ++i)
  644. {
  645.  
  646. // --- Wage Rate: check for new min and/or max ---
  647. if (employeeData[i].wageRate < employeeMinMax.min_wageRate)
  648. {
  649. employeeMinMax.min_wageRate = employeeData[i].wageRate;
  650. }
  651. if (employeeData[i].wageRate > employeeMinMax.max_wageRate)
  652. {
  653. employeeMinMax.max_wageRate = employeeData[i].wageRate;
  654. }
  655.  
  656. // --- Hours: check for new min and/or max ---
  657. if (employeeData[i].hours < employeeMinMax.min_hours)
  658. {
  659. employeeMinMax.min_hours = employeeData[i].hours;
  660. }
  661. if (employeeData[i].hours > employeeMinMax.max_hours)
  662. {
  663. employeeMinMax.max_hours = employeeData[i].hours;
  664. }
  665.  
  666. // --- Overtime Hours: check for new min and/or max ---
  667. if (employeeData[i].overtimeHrs < employeeMinMax.min_overtimeHrs)
  668. {
  669. employeeMinMax.min_overtimeHrs = employeeData[i].overtimeHrs;
  670. }
  671. if (employeeData[i].overtimeHrs > employeeMinMax.max_overtimeHrs)
  672. {
  673. employeeMinMax.max_overtimeHrs = employeeData[i].overtimeHrs;
  674. }
  675.  
  676. // --- Gross Pay: check for new min and/or max ---
  677. if (employeeData[i].grossPay < employeeMinMax.min_grossPay)
  678. {
  679. employeeMinMax.min_grossPay = employeeData[i].grossPay;
  680. }
  681. if (employeeData[i].grossPay > employeeMinMax.max_grossPay)
  682. {
  683. employeeMinMax.max_grossPay = employeeData[i].grossPay;
  684. }
  685.  
  686. // --- State Tax: check for new min and/or max ---
  687. if (employeeData[i].stateTax < employeeMinMax.min_stateTax)
  688. {
  689. employeeMinMax.min_stateTax = employeeData[i].stateTax;
  690. }
  691. if (employeeData[i].stateTax > employeeMinMax.max_stateTax)
  692. {
  693. employeeMinMax.max_stateTax = employeeData[i].stateTax;
  694. }
  695.  
  696. // --- Federal Tax: check for new min and/or max ---
  697. if (employeeData[i].fedTax < employeeMinMax.min_fedTax)
  698. {
  699. employeeMinMax.min_fedTax = employeeData[i].fedTax;
  700. }
  701. if (employeeData[i].fedTax > employeeMinMax.max_fedTax)
  702. {
  703. employeeMinMax.max_fedTax = employeeData[i].fedTax;
  704. }
  705.  
  706. // --- Net Pay: check for new min and/or max ---
  707. if (employeeData[i].netPay < employeeMinMax.min_netPay)
  708. {
  709. employeeMinMax.min_netPay = employeeData[i].netPay;
  710. }
  711. if (employeeData[i].netPay > employeeMinMax.max_netPay)
  712. {
  713. employeeMinMax.max_netPay = employeeData[i].netPay;
  714. }
  715.  
  716. } // for
  717.  
  718. // return all the updated min and max values to the calling function
  719. return (employeeMinMax);
  720.  
  721. } // calcEmployeeMinMax
Success #stdin #stdout 0s 5308KB
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