fork download
  1. //Jonathan Messiha CS1A Practicum #1
  2. //
  3. /* *****************************************************************************
  4.  * _____________________________________________________________________________
  5.  * This program will ask a user to enter financial information for however many
  6.  * employees and then use a loop to accumulate and display all totals over a
  7.  * specified week.
  8.  *
  9.  * Computation is based on the following equations:
  10.  * grossTotal += grossPay
  11.  * stateTotal += stateTax
  12.  * federalTotal += federalTax;
  13.  * ficaTotal += ficaWithhold;
  14.  * netPay = grossPay - (stateTax + federalTax + ficaWithhold)
  15.  * netTotal += netPay
  16.  *______________________________________________________________________________
  17.  * INPUT
  18.  * employeeNum: random form of employee identification. Also serves as sentinel.
  19.  * grossPay: gross pay for each employee for this week.
  20.  * stateTax: state tax owed by each employee this week.
  21.  * federalTax: federal tax owed by each employee this week.
  22.  * ficaWithhold: FICA withheld from each employee this week.
  23.  *
  24.  * OUTPUT
  25.  * grossTotal: total gross pay of all employees this week.
  26.  * stateTotal: total state tax of all employees this week.
  27.  * federalTotal: total federal tax of all employees this week.
  28.  * ficaTotal: total FICA withheld from all employees this week.
  29.  * netTotal: net total pay for all employees this week.
  30.  ******************************************************************************/
  31. #include <iostream>
  32. #include <iomanip>
  33. using namespace std;
  34.  
  35. int main() {
  36.  
  37. // identify variables and initialize count to 0.
  38. int employeeNum, count = 0;
  39.  
  40. // identify gross pay variables and initialize total to 0.
  41. double grossPay, grossTotal = 0;
  42.  
  43. // identify state tax variables and initialize total to 0.
  44. double stateTax, stateTotal = 0;
  45.  
  46. // identify federal tax variables and initialize total to 0.
  47. double federalTax, federalTotal = 0;
  48.  
  49. // identify FICA variables and initialize total to 0.
  50. double ficaWithhold, ficaTotal = 0;
  51.  
  52. // identify net pay variables and initialize total to 0.
  53. double netPay, netTotal = 0;
  54.  
  55. // Asks for and receives employee number from user.
  56. cout << "Enter employee #:" << endl;
  57. cin >> employeeNum;
  58.  
  59. // While loop that runs while employee number is not 0 (sentinel)
  60. while (employeeNum != 0)
  61. {
  62. // adds 1 to count to keep track of loop and number of employees entered
  63. count += 1;
  64.  
  65. // Asks for and receives gross pay and then begins to accumulate a total.
  66. cout << "Enter gross pay for employee " << count << endl;
  67. cin >> grossPay;
  68. grossTotal += grossPay;
  69.  
  70. // Asks for and receives sales tax and then begins to accumulate a total.
  71. cout << "Enter state tax for employee " << count << endl;
  72. cin >> stateTax;
  73. stateTotal += stateTax;
  74.  
  75. // Asks for and receives federal tax and then begins to accumulate a total.
  76. cout << "Enter federal tax for employee " << count << endl;
  77. cin >> federalTax;
  78. federalTotal += federalTax;
  79.  
  80. // Asks for and receives FICA withholdings and then begins to accumulate
  81. // a total.
  82. cout << "Enter FICA withholdings for employee " << count << endl;
  83. cin >> ficaWithhold;
  84. ficaTotal += ficaWithhold;
  85.  
  86. // computations for netPay and netTotal.
  87. netPay = grossPay - (stateTax + federalTax + ficaWithhold);
  88. netTotal += netPay;
  89.  
  90. // Asks for next employee # before loop restarts. If 0, loop will end.
  91. cout << "Enter next employee #" << endl;
  92. cin >> employeeNum;
  93. }
  94. // end of loop
  95.  
  96. // sets output formatting to 2 decimal places.
  97. cout << setprecision(2) << fixed << endl;
  98.  
  99. // Output table headers.
  100. cout << "Gross Pay: \t State Tax: \t Federal Tax: \t ";
  101. cout << "FICA Withholdings: \t Net Pay:" << endl;
  102.  
  103. // Output data with proper tabular formatting.
  104. cout << "$" << grossTotal << "\t $" << stateTotal << "\t\t $";
  105. cout << federalTotal << "\t\t $" << ficaTotal << "\t\t\t\t $";
  106. cout << netTotal << endl;
  107.  
  108. return 0;
  109. }
Success #stdin #stdout 0.01s 5508KB
stdin
238621
1386.22
103.12
208.56
125.00
513782
2508.00
152.33
301.19
175.00
312423
1975.66
143.78
298.11
168.00
432152
980.55
76.23
88.54
98.00
601932
2930.00
203.94
350.25
200.00
0
stdout
Enter employee #:
Enter gross pay for employee 1
Enter state tax for employee 1
Enter federal tax for employee 1
Enter FICA withholdings for employee 1
Enter next employee #
Enter gross pay for employee 2
Enter state tax for employee 2
Enter federal tax for employee 2
Enter FICA withholdings for employee 2
Enter next employee #
Enter gross pay for employee 3
Enter state tax for employee 3
Enter federal tax for employee 3
Enter FICA withholdings for employee 3
Enter next employee #
Enter gross pay for employee 4
Enter state tax for employee 4
Enter federal tax for employee 4
Enter FICA withholdings for employee 4
Enter next employee #
Enter gross pay for employee 5
Enter state tax for employee 5
Enter federal tax for employee 5
Enter FICA withholdings for employee 5
Enter next employee #

Gross Pay: 	 State Tax: 	 Federal Tax: 	 FICA Withholdings: 	 Net Pay:
$9780.43	 $679.40		 $1246.65		 $766.00				 $7088.38