fork download
  1. //*******************************************************
  2.  
  3. //
  4.  
  5. // Assignment 3 - Conditionals
  6.  
  7. //
  8.  
  9. // Name: Sovanna Mann
  10.  
  11. //
  12.  
  13. // Class: C Programming, Fall 2024
  14.  
  15. //
  16.  
  17. // Date: 9/27/2024
  18.  
  19. //
  20.  
  21. // Description: Program which determines overtime and
  22.  
  23. // gross pay for a set of employees with outputs sent
  24.  
  25. // to standard output (the screen).
  26.  
  27. //
  28.  
  29. //********************************************************
  30.  
  31.  
  32.  
  33. #include <stdio.h>
  34.  
  35.  
  36.  
  37. // Declare constants
  38.  
  39. #define STD_HOURS 40.0
  40.  
  41. #define NUM_EMPLOYEES 5
  42.  
  43. #define OVERTIME_RATE 1.5
  44.  
  45.  
  46.  
  47. // TODO: Declare and use at least one more constant
  48.  
  49.  
  50.  
  51. int main()
  52.  
  53. {
  54.  
  55. int clockNumber; // Employee clock number
  56.  
  57. float grossPay; // The weekly gross pay which is the normalPay + any overtimePay
  58.  
  59. float hours; // Total hours worked in a week
  60.  
  61. float normalPay; // Standard weekly normal pay without overtime
  62.  
  63. float overtimeHrs; // Overtime hours worked beyond a normal week (40 hours)
  64.  
  65. float overtimePay; // Any hours worked past the normal scheduled work week
  66.  
  67. float wageRate; // Hourly wage for an employee
  68.  
  69.  
  70.  
  71. printf ("\n*** Pay Calculator ***");
  72.  
  73.  
  74.  
  75. // Process each employee
  76.  
  77. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  78.  
  79.  
  80.  
  81. // Prompt the user for the clock number
  82.  
  83. printf("\n\nEnter clock number: ");
  84.  
  85. scanf("%d", &clockNumber);
  86.  
  87.  
  88.  
  89. // Prompt the user for the wage rate
  90.  
  91. printf("\nEnter wage rate: ");
  92.  
  93. scanf("%f", &wageRate);
  94.  
  95.  
  96.  
  97. // Prompt the user for the number of hours worked
  98.  
  99. printf("\nEnter number of hours worked: ");
  100.  
  101. scanf("%f", &hours);
  102.  
  103.  
  104.  
  105. // Optional TODO: Remove these initialization statements if desired
  106.  
  107. // initialize so initial template prints these both as zero
  108.  
  109. grossPay = 0;
  110.  
  111. overtimeHrs = 0;
  112.  
  113. overtimePay = 0;
  114.  
  115. normalPay = 0;
  116.  
  117.  
  118.  
  119. // Calculate the overtime hours, normal pay, and overtime pay
  120.  
  121. if (hours > STD_HOURS) {
  122.  
  123. overtimeHrs = hours - STD_HOURS;
  124.  
  125. normalPay = wageRate * STD_HOURS;
  126.  
  127. overtimePay = (OVERTIME_RATE * wageRate) * overtimeHrs;
  128.  
  129.  
  130.  
  131. // TODO: calculate the three values with overtime
  132.  
  133. } else {
  134.  
  135. normalPay = wageRate * hours;
  136.  
  137. // TODO: calculate the three values without overtime
  138.  
  139. }
  140.  
  141.  
  142.  
  143. // Calculate the gross pay with normal pay and any additional overtime pay
  144.  
  145. grossPay = normalPay + overtimePay;
  146.  
  147.  
  148.  
  149. // Print out information on the current employee
  150.  
  151. // Optional TODO: Feel free to also print out normalPay and overtimePay
  152.  
  153. printf("\n\nClock# Wage Hours OT Gross\n");
  154.  
  155. printf("------------------------------------------------\n");
  156.  
  157. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  158.  
  159. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  160.  
  161. }
  162.  
  163.  
  164.  
  165. return 0;
  166.  
  167. }
Success #stdin #stdout 0s 5284KB
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