fork download
  1. //Jonathan Estrada CSC5 page#650 chapter 11 #15
  2. /*************************************************************************
  3.  * COMPUTE PAY
  4.  * _______________________________________________________________________
  5.  * This program will compute the pay based on pay choice either hourly or
  6.  * salary. Then it will display it for the worker.
  7.  * _______________________________________________________________________
  8.  * INPUT
  9.  * payType : choice for type of pay
  10.  * hours Worked : hours worked
  11.  * hourlyRate : hourly rate
  12.  * salary : salary pay
  13.  * bonus : bonus for salary pay
  14.  *
  15.  * OUTPUT
  16.  * pay : pay based off pay type
  17.  * **********************************************************************/
  18.  
  19.  
  20. #include <iostream>
  21. #include <cctype>
  22. using namespace std;
  23.  
  24. struct hourlyPaid
  25. {
  26. int hoursWorked;
  27. float hourlyRate;
  28. };
  29.  
  30. struct salaried
  31. {
  32. float salary;
  33. float bonus;
  34. };
  35.  
  36. union employee
  37. {
  38. hourlyPaid hours;
  39. salaried paid;
  40. };
  41. int main() {
  42. char payType;
  43. float pay;
  44. employee worker;
  45.  
  46. cout << "Please enter 'H' for hourly pay or 'S' for salary pay: ";
  47. cin >> payType;
  48. while(toupper(payType) != 'H' && toupper(payType) != 'S')
  49. {
  50. cout << "Invalid must be 'H' or 'S'" << endl;
  51. cout << "Please enter 'H' for hourly pay or 'S' for salary pay: ";
  52. cin >> payType;
  53. }
  54. if(toupper(payType) == 'H')
  55. {
  56. cout << "Please enter hours worked: ";
  57. cin >> worker.hours.hoursWorked;
  58. cout << worker.hours.hoursWorked << endl;
  59. cout << "Please enter hourly rate: ";
  60. cin >> worker.hours.hourlyRate;
  61. cout << worker.hours.hourlyRate << endl;
  62. pay = worker.hours.hoursWorked * worker.hours.hourlyRate;
  63. cout << "Workers total hourly pay: $" << pay << endl;
  64. }
  65. else if(toupper(payType) == 'S')
  66. {
  67. cout << "Please enter salary: ";
  68. cin >> worker.paid.salary;
  69. cout << worker.paid.salary << endl;
  70. cout << "Please enter bonus: ";
  71. cin >> worker.paid.bonus;
  72. cout << worker.paid.bonus << endl;
  73. pay = worker.paid.salary + worker.paid.bonus;
  74. cout << "Workers total salary pay is: $" << pay << endl;
  75. }
  76. return 0;
  77. }
Success #stdin #stdout 0.01s 5284KB
stdin
H
40
15.50
stdout
Please enter 'H' for hourly pay or 'S' for salary pay: Please enter hours worked: 40
Please enter hourly rate: 15.5
Workers total hourly pay: $620