fork download
  1. //*******************************************************
  2. //
  3. // Assignment 3 - Conditionals
  4. //
  5. // Name: <replace with your name>
  6. //
  7. // Class: C Programming, <replace with Semester and Year>
  8. //
  9. // Date: <replace with the current date>
  10. //
  11. // Description: Program which determines overtime and
  12. // gross pay for a set of employees with outputs sent
  13. // to standard output (the screen).
  14. //
  15. //********************************************************
  16.  
  17.  
  18.  
  19.  
  20. #include <stdio.h>
  21.  
  22.  
  23. // Declare constants
  24. #define STD_HOURS 40.0
  25. #define NUM_EMPLOYEES 5
  26. #define OT_RATE 1.5 // Overtime pay multiplier
  27.  
  28. int main()
  29. {
  30. int clockNumber; // Employee clock number
  31. float grossPay; // Total gross pay
  32. float hours; // Hours worked in a week
  33. float normalPay; // Standard pay for week (up to 40 hours)
  34. float overtimeHrs; // Hours worked past 40 hr week
  35. float overtimePay; // For going beyond +ultra
  36. float wageRate; // Hourly pay for your peeps
  37.  
  38. printf("\n*** Pay Calculator ***");
  39.  
  40. // Process each employee
  41. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  42.  
  43. // Prompt user for clock number, them wage rate, then hours worked
  44. printf("\n\nEnter clock number: ");
  45. scanf("%d", &clockNumber);
  46.  
  47. printf("Enter wage rate: ");
  48. scanf("%f", &wageRate);
  49.  
  50. printf("Enter number of hours worked: ");
  51. scanf("%f", &hours);
  52.  
  53. // Calculate pay
  54. if (hours > STD_HOURS) {
  55. overtimeHrs = hours - STD_HOURS;
  56. normalPay = STD_HOURS * wageRate;
  57. overtimePay = overtimeHrs * wageRate * OT_RATE;
  58. } else {
  59. overtimeHrs = 0;
  60. normalPay = hours * wageRate;
  61. overtimePay = 0;
  62. }
  63.  
  64. grossPay = normalPay + overtimePay;
  65.  
  66. // Output results
  67. printf("\n\nClock# Wage Hours OT Gross\n");
  68. printf("-------------------------------------\n");
  69. printf("%06d %6.2f %6.1f %6.1f %8.2f\n",
  70. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  71. } // for
  72.  
  73. return 0;
  74. } // Sucess
Success #stdin #stdout 0s 5320KB
stdin
 98401  10.60   51.0   
526488   9.75   42.5   
765349  10.50   37.0   
34645  12.25   45.0   
127615   8.35    0.0
stdout
*** Pay Calculator ***

Enter clock number: Enter wage rate: Enter number of hours worked: 

Clock#  Wage   Hours   OT   Gross
-------------------------------------
098401  10.60   51.0   11.0   598.90


Enter clock number: Enter wage rate: Enter number of hours worked: 

Clock#  Wage   Hours   OT   Gross
-------------------------------------
526488   9.75   42.5    2.5   426.56


Enter clock number: Enter wage rate: Enter number of hours worked: 

Clock#  Wage   Hours   OT   Gross
-------------------------------------
765349  10.50   37.0    0.0   388.50


Enter clock number: Enter wage rate: Enter number of hours worked: 

Clock#  Wage   Hours   OT   Gross
-------------------------------------
034645  12.25   45.0    5.0   581.88


Enter clock number: Enter wage rate: Enter number of hours worked: 

Clock#  Wage   Hours   OT   Gross
-------------------------------------
127615   8.35    0.0    0.0     0.00