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. #include <stdio.h>
  18.  
  19. // Declare constants
  20. #define STD_HOURS 40.0
  21. #define NUM_EMPLOYEES 5
  22. #define OT_RATE 1.5 // Overtime pay multiplier
  23.  
  24. int main() {
  25. int clockNumber; // Employee clock number
  26. float grossPay; // Total gross pay
  27. float hours; // Hours worked in a week
  28. float normalPay; // Standard pay (up to 40 hours)
  29. float overtimeHrs; // Hours worked beyond standard
  30. float overtimePay; // Extra pay for overtime
  31. float wageRate; // Hourly pay rate
  32.  
  33. printf("\n*** Pay Calculator ***");
  34.  
  35. // Process each employee
  36. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  37. // Input data
  38. printf("\n\nEnter clock number: ");
  39. scanf("%d", &clockNumber);
  40.  
  41. printf("Enter wage rate: ");
  42. scanf("%f", &wageRate);
  43.  
  44. printf("Enter number of hours worked: ");
  45. scanf("%f", &hours);
  46.  
  47. // Calculate pay
  48. if (hours > STD_HOURS) {
  49. overtimeHrs = hours - STD_HOURS;
  50. normalPay = STD_HOURS * wageRate;
  51. overtimePay = overtimeHrs * wageRate * OT_RATE;
  52. } else {
  53. overtimeHrs = 0;
  54. normalPay = hours * wageRate;
  55. overtimePay = 0;
  56. }
  57.  
  58. grossPay = normalPay + overtimePay;
  59.  
  60. // Output results
  61. printf("\n\nClock# Wage Hours OT Gross\n");
  62. printf("-------------------------------------\n");
  63. printf("%06d %6.2f %6.1f %6.1f %8.2f\n",
  64. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  65. } // for
  66.  
  67. return 0;
  68. } // main
Success #stdin #stdout 0s 5316KB
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