fork download
  1. //Nathan Dominguez CSC5 Chapter 7, p. 445, #8
  2. //
  3. /*******************************************************************************
  4. *
  5. * Compute Payroll
  6. *_______________________________________________________________________________
  7. * This program will ask the user for their payrate and the number
  8. * of hours that they worked, then calculate their wages. It will
  9. * display the employee number and their associated gross wages.
  10. *_______________________________________________________________________________
  11. * Input
  12. * payrate[count] : Employee's inputted payrate
  13. * hours[count] : Employee's inputted hours
  14. *
  15. * Output
  16. * wages[count] : gross wage for each employee
  17. * empID[count] : employee ID
  18. *
  19. *************************************************************************/
  20. #include <iostream>
  21. #include <iomanip>
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26. //declare variables
  27. const int numEmployee = 7; //CONST - number of employees
  28. long empID[7] = {5658845, 4520125, 7895122, 8777541,
  29. 8451277, 1302850, 7580489}; //OUTPUT - employee ID
  30. int hours[7]; //INPUT - employee hours
  31. double payRate[7]; //INPUT - employee pay rate
  32. double wages[7]; //OUTPUT - employee's gross wage
  33. int count; //LOOP - counter
  34. //
  35. //loop program seven times
  36. for (count = 0; count < numEmployee; count++)
  37. {
  38. cout << "Employee #" << empID[count] << ": " << endl;
  39. cout << "Enter amount of hours worked: ";
  40. cin >> hours[count];
  41. cout << endl;
  42. //
  43. //input validation
  44. if (hours[count] < 0)
  45. {
  46. cout << "Invalid, please try again." << endl;
  47. cout << "Enter amount of hours worked: ";
  48. cin >> hours[count];
  49. cout << endl;
  50. }
  51. cout << "Enter pay rate: ";
  52. cin >> payRate[count];
  53. cout << endl;
  54. //
  55. //input validation
  56. if (payRate[count] < 6.00)
  57. {
  58. cout << "Invalid, please try again. " << endl;
  59. cout << "Enter pay rate: ";
  60. cin >> payRate[count];
  61. payRate[count] = payRate[count] / 100;
  62. cout << endl;
  63. }
  64. //calculate gross wages
  65. wages[count] = hours[count] * payRate[count];
  66. cout << endl;
  67. }
  68.  
  69. // output payroll
  70. cout << "Payroll Report (Gross Wages): " << endl;
  71. for (count = 0; count < numEmployee; count++)
  72. {
  73. cout << "#" << empID[count] << ": $" << wages[count] << endl;
  74. }
  75. return 0;
  76. }
Success #stdin #stdout 0.01s 5304KB
stdin
1
8
1
8
1
8
1
8
1
8
1
8
1
8
stdout
Employee #5658845: 
Enter amount of hours worked: 
Enter pay rate: 

Employee #4520125: 
Enter amount of hours worked: 
Enter pay rate: 

Employee #7895122: 
Enter amount of hours worked: 
Enter pay rate: 

Employee #8777541: 
Enter amount of hours worked: 
Enter pay rate: 

Employee #8451277: 
Enter amount of hours worked: 
Enter pay rate: 

Employee #1302850: 
Enter amount of hours worked: 
Enter pay rate: 

Employee #7580489: 
Enter amount of hours worked: 
Enter pay rate: 

Payroll Report (Gross Wages): 
#5658845: $8
#4520125: $8
#7895122: $8
#8777541: $8
#8451277: $8
#1302850: $8
#7580489: $8