fork download
  1. //Jeremy Huang CS1A Practicum
  2. //
  3. /******************************************************************************
  4.  * CALCULATE WEEKLY PAYROLL REPORT
  5.  *
  6.  ******************************************************************************
  7.  * This program calculates a weekly payroll report based on input
  8.  * of the gross pay, state tax, federal tax, FICA withholdings, and employee
  9.  * number of each employee.
  10.  *
  11.  * ****************************************************************************
  12.  * INPUTS
  13.  * employee_num : the id of the employee
  14.  * grossPay : gross pay of the employee
  15.  * stateTax : state tax for the employee
  16.  * federalTax : federal tax for the employee
  17.  * ficawithholdings : FICA withholdings for the employee
  18.  *
  19.  * OUTPUTS
  20.  * gross_pay_total : gross pay total for all employees
  21.  * state_tax_total : state tax total for all employees
  22.  * federal_tax_total : federal tax total for all employees
  23.  * fica_withholdings_total : FICA withholdings total for all employees
  24.  * netPay : the net pay for all employees
  25.  ******************************************************************************/
  26.  
  27. #include <iostream>
  28. #include <iomanip>
  29. using namespace std;
  30.  
  31. int main() {
  32. //Initializing variables
  33. int employee_num;
  34. double grossPay;
  35. double stateTax;
  36. double federalTax;
  37. double fica_withholdings;
  38. double netPay;
  39.  
  40. double gross_pay_total = 0;
  41. double state_tax_total = 0;
  42. double federal_tax_total = 0;
  43. double fica_withholdings_total = 0;
  44.  
  45. cout<<"Please enter the employee number (Enter 0 to terminate): "<<endl;
  46. cin>>employee_num;
  47.  
  48. //Loop, input
  49. while (employee_num != 0)
  50. {
  51. cout<<"Please enter the gross pay for employee "<<employee_num<<": "<<endl;
  52. cin>>grossPay;
  53. cout<<"Please enter the state tax for employee "<<employee_num<<": "<<endl;
  54. cin>>stateTax;
  55. cout<<"Please enter the federal tax for employee "<<employee_num<<": "<<endl;
  56. cin>>federalTax;
  57. cout<<"Please enter the FICA withholdings for employee "
  58. <<employee_num<<": "<<endl;
  59. cin>>fica_withholdings;
  60. cout<<"Please enter the employee number (Enter 0 to terminate): "<<endl;
  61. cin>>employee_num;
  62.  
  63. //Accumulators
  64. gross_pay_total+=grossPay;
  65. state_tax_total+=stateTax;
  66. federal_tax_total+=federalTax;
  67. fica_withholdings_total+=fica_withholdings;
  68. }
  69.  
  70. //Net pay calculation
  71. netPay = gross_pay_total -
  72. (state_tax_total+federal_tax_total+fica_withholdings_total);
  73.  
  74. //Formatting output
  75. cout<<showpoint<<fixed<<setprecision(2)<<endl<<endl;
  76. cout<<"Gross Pay"<<setw(14)<<"State Tax"<<setw(16)<<"Federal Tax"
  77. <<setw(22)<<"FICA Withholdings"<<setw(12)<<"Net Pay"<<endl;
  78. cout<<gross_pay_total<<setw(13)<<state_tax_total<<setw(15)
  79. <<federal_tax_total <<setw(15)<<fica_withholdings_total
  80. <<setw(23)<<netPay<<endl;
  81.  
  82. return 0;
  83. }
Success #stdin #stdout 0.01s 5300KB
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
Please enter the employee number (Enter 0 to terminate): 
Please enter the gross pay for employee 238621: 
Please enter the state tax for employee 238621: 
Please enter the federal tax for employee 238621: 
Please enter the FICA withholdings for employee 238621: 
Please enter the employee number (Enter 0 to terminate): 
Please enter the gross pay for employee 513782: 
Please enter the state tax for employee 513782: 
Please enter the federal tax for employee 513782: 
Please enter the FICA withholdings for employee 513782: 
Please enter the employee number (Enter 0 to terminate): 
Please enter the gross pay for employee 312423: 
Please enter the state tax for employee 312423: 
Please enter the federal tax for employee 312423: 
Please enter the FICA withholdings for employee 312423: 
Please enter the employee number (Enter 0 to terminate): 
Please enter the gross pay for employee 432152: 
Please enter the state tax for employee 432152: 
Please enter the federal tax for employee 432152: 
Please enter the FICA withholdings for employee 432152: 
Please enter the employee number (Enter 0 to terminate): 
Please enter the gross pay for employee 601932: 
Please enter the state tax for employee 601932: 
Please enter the federal tax for employee 601932: 
Please enter the FICA withholdings for employee 601932: 
Please enter the employee number (Enter 0 to terminate): 


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