fork download
  1. // Practicum 1: Ryan Shahriyarpour CS1A Carl Argila MCS Building
  2. /*****************************
  3.  *
  4.  * Compute Weekly Payroll
  5.  *
  6.  * ***************************
  7.  *
  8.  * This program prompts the user for an employee number, gross pay,
  9.  * state tax, federal tax, and FICA withholdings for each employee.
  10.  * The loop will repeat until the sentinel value 0 is entered for the
  11.  * employee number.
  12.  *
  13.  * After all data is entered, the program will display a weekly payroll
  14.  * report on two lines: a line of column headers followed by a line
  15.  * of totals for gross pay, state tax, federal tax, FICA
  16.  * withholdings, and net pay for all employees.
  17.  *
  18.  * Net Pay Formula:
  19.  * Net Pay = Gross Pay - (State Tax + Federal Tax + FICA Withholdings)
  20.  * ****************************
  21.  *
  22.  * Variables:
  23.  *
  24.  * grossPay = gross pay
  25.  * stateTax = state tax
  26.  * fedTax = federal tax
  27.  * fica = FICA withholdings
  28.  * totalGross = total gross payment
  29.  * totalState = total state tax paid
  30.  * totalFed = total federal tax paid
  31.  * totalFica = total FICA withholdings
  32.  * netPay = total net payment
  33.  *
  34.  *
  35.  * ****************************/
  36.  
  37.  
  38. #include <iostream>
  39. #include <iomanip>
  40. using namespace std;
  41.  
  42. int main()
  43. {
  44. //declare the variables
  45. int empNum;
  46. double grossPay, stateTax, fedTax, fica;
  47. double totalGross = 0, totalState = 0, totalFed = 0, totalFica = 0;
  48. double netPay;
  49.  
  50. //read the employee numbers until sentinal value 0 is entered
  51. cout << "Enter employee number (0 to quit): ";
  52. cin >> empNum;
  53.  
  54. while (empNum != 0)
  55. {
  56.  
  57. cout << "Enter your gross pay: ";
  58. cin >> grossPay;
  59. cout << "Enter the state tax: ";
  60. cin >> stateTax;
  61. cout << "Enter the federal tax: ";
  62. cin >> fedTax;
  63. cout << "Enter FICA withholdings: ";
  64. cin >> fica;
  65.  
  66.  
  67. totalGross = totalGross + grossPay;
  68. totalState = totalState + stateTax;
  69. totalFed = totalFed + fedTax;
  70. totalFica = totalFica + fica;
  71.  
  72.  
  73. cout << "Enter employee number (0 to quit): " << endl;
  74. cin >> empNum;
  75. }
  76.  
  77. //Calculate total net pay with formula
  78. netPay = totalGross - (totalState + totalFed + totalFica);
  79.  
  80. //Display the payroll using 2 lines
  81. cout << " " << endl;
  82. cout << "Weekly Payroll Report";
  83. cout << fixed << setprecision(2) << endl;
  84. cout << left << setw(14) << "Gross Pay"
  85. << setw(14) << "State Tax"
  86. << setw(14) << "Federal Tax"
  87. << setw(14) << "FICA"
  88. << setw(14) << "Net Pay" << endl;
  89. cout << left << setw(14) << totalGross
  90. << setw(14) << totalState
  91. << setw(14) << totalFed
  92. << setw(14) << totalFica
  93. << setw(14) << netPay << endl;
  94.  
  95. return 0;
  96. }
Success #stdin #stdout 0s 5316KB
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 number (0 to quit): Enter your gross pay: Enter the state tax: Enter the federal tax: Enter FICA withholdings: Enter employee number (0 to quit): 
Enter your gross pay: Enter the state tax: Enter the federal tax: Enter FICA withholdings: Enter employee number (0 to quit): 
Enter your gross pay: Enter the state tax: Enter the federal tax: Enter FICA withholdings: Enter employee number (0 to quit): 
Enter your gross pay: Enter the state tax: Enter the federal tax: Enter FICA withholdings: Enter employee number (0 to quit): 
Enter your gross pay: Enter the state tax: Enter the federal tax: Enter FICA withholdings: Enter employee number (0 to quit): 
 
Weekly Payroll Report
Gross Pay     State Tax     Federal Tax   FICA          Net Pay       
9780.43       679.40        1246.65       766.00        7088.38