fork download
  1. // Saliha Babar CS1A Chapter 7, Page 445, #8
  2. //
  3. /***************************************************************************
  4.  * DISPLAY PAYROLL REPORT
  5.  * ________________________________________________________________________
  6.  * This program accepts hours worked and pay rate(dollar per hour) for 7
  7.  * employees. This program then, calculates the wages for each employee and
  8.  * display a payroll report.
  9.  *
  10.  * Formula related to this program
  11.  * wages = hours * payRate
  12.  * __________________________________________________________________________
  13.  * INPUT
  14.  * hours : hours worked by each employee
  15.  * payRate : pay rate for each employee
  16.  *
  17.  * OUTPUT
  18.  * wages : wages for each employee
  19.  * *************************************************************************/
  20.  
  21. #include <iostream>
  22. #include <iomanip>
  23. using namespace std;
  24.  
  25. int main() {
  26. const int NUM_EMPLOYEES=7;
  27. long int empId[NUM_EMPLOYEES] = { 5658845, 4520125, 7895122, 8777541,
  28. 8451277, 1302850, 7580489 };
  29. int hours [NUM_EMPLOYEES]; // INPUT - hours worked by each employee
  30. double payRate [NUM_EMPLOYEES]; // INPUT - pay rate of each employee
  31. double wages[NUM_EMPLOYEES]; // OUTPUT - wages of each employee
  32.  
  33. for (int i = 0; i < NUM_EMPLOYEES ; i++)
  34. {
  35. cout << "Enter hours worked by employee #" << empId[i];
  36. cin >> hours[i];
  37.  
  38. while (hours[i] < 0)
  39. {
  40. cout << "Only enter positive values.\n";
  41. cin >> hours[i];
  42. }
  43.  
  44. cout << "\nEnter the pay rate per hour (in $) for employee #" << empId[i];
  45. cin >> payRate[i];
  46.  
  47. while (payRate [i] < 6.00)
  48. {
  49. cout << "Only enter pay rate that is greater than 6.00$\n";
  50. cin >> payRate[i];
  51. }
  52. cout << endl << endl;
  53. }
  54.  
  55. // Display the output
  56. cout << "Employee Id\t\tHours Worked\tPay Rate($)\tWages($)\n";
  57. cout << "___________________________________________________\n";
  58. for ( int i = 0; i < NUM_EMPLOYEES ; i++ )
  59. {
  60. wages[i]= hours[i] * payRate[i];
  61. cout << setw(11) <<empId[i];
  62. cout << setw(16) << hours[i];
  63. cout << fixed << setprecision(2);
  64. cout << setw(14) << payRate[i];
  65. cout << setw(10) << wages[i] << endl;
  66. }
  67. return 0;
  68. }
Success #stdin #stdout 0.01s 5284KB
stdin
10
13.5
8
11.5
9
14.9
4
20.0
5
19
6
15.5
8
16.9
stdout
Enter hours worked by employee #5658845
Enter the pay rate per hour (in $) for employee #5658845

Enter hours worked by employee #4520125
Enter the pay rate per hour (in $) for employee #4520125

Enter hours worked by employee #7895122
Enter the pay rate per hour (in $) for employee #7895122

Enter hours worked by employee #8777541
Enter the pay rate per hour (in $) for employee #8777541

Enter hours worked by employee #8451277
Enter the pay rate per hour (in $) for employee #8451277

Enter hours worked by employee #1302850
Enter the pay rate per hour (in $) for employee #1302850

Enter hours worked by employee #7580489
Enter the pay rate per hour (in $) for employee #7580489

Employee Id		Hours Worked	Pay Rate($)	Wages($)
___________________________________________________
    5658845              10         13.50    135.00
    4520125               8         11.50     92.00
    7895122               9         14.90    134.10
    8777541               4         20.00     80.00
    8451277               5         19.00     95.00
    1302850               6         15.50     93.00
    7580489               8         16.90    135.20