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. // TODO: Declare and use one more constant
  23.  
  24. int main()
  25. {
  26.  
  27. int clockNumber; // Employee clock number
  28. float grossPay; // The weekly gross pay which is the normalPay + any overtimePay
  29. float hours; // Total hours worked in a week
  30. float normalPay; // Standard weekly normal pay without overtime
  31. float overtimeHrs; // Any hours worked past the normal scheduled work week
  32. float overtimePay; // Additional overtime pay for any overtime hours worked
  33. float wageRate; // Hourly wage for an employee
  34.  
  35. printf ("\n*** Pay Calculator ***");
  36.  
  37. // Process each employee
  38. for (int i = 0; i < NUM_EMPLOYEES; i++) {
  39.  
  40. // Prompt the user for the clock number
  41. printf("\n\nEnter clock number: ");
  42. scanf("%d", &clockNumber);
  43.  
  44. // Prompt the user for the wage rate
  45. printf("\nEnter wage rate: ");
  46. scanf("%f", &wageRate);
  47.  
  48. // Prompt the user for the number of hours worked
  49. printf("\nEnter number of hours worked: ");
  50. scanf("%f", &hours);
  51.  
  52. // Optional TODO: Remove these two statements if desired
  53. // ... were added just for the template to print some values out of the box
  54. grossPay = 0;
  55. overtimeHrs = 0;
  56.  
  57. // Calculate the overtime hours, normal pay, and overtime pay
  58. if (hours > STD_HOURS) {
  59. // TODO: calculate the three values with overtime
  60. } else {
  61. // TODO: calculate the three values without overtime
  62. }
  63.  
  64. // Calculate the gross pay with normal pay and any additional overtime pay
  65. grossPay = normalPay + overtimePay;
  66.  
  67. // Print out information on the current employee
  68. // Optional TODO: Feel free to also print out normalPay and overtimePay
  69. printf("\n\nClock# Wage Hours OT Gross\n");
  70. printf("------------------------------------------------\n");
  71. printf("%06d %5.2f %5.1f %5.1f %8.2f\n",
  72. clockNumber, wageRate, hours, overtimeHrs, grossPay);
  73. }
  74.  
  75. return 0;
  76. }
Success #stdin #stdout 0s 5276KB
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  

#include <stdio.h>

#define SIZE 5
#define STD_HOURS 40.0

int main() 
{   
    int clockNumber;
    float wageRate, hours, normalPay, overtimeHours, overtimePay, grossPay;

    printf("\n*** Pay Calculator ***");

    // Process each employee
    for (int i = 1; i <= SIZE; ++i) {
        
        // Prompt the user for the clock number
        printf("\n\nEnter clock number for employee %d: ", i);
        scanf("%d", &clockNumber);

        // Prompt the user for the wage rate
        printf("Enter wage rate for employee %d: ", i);
        scanf("%f", &wageRate);

        // Prompt the user for the number of hours worked
        printf("Enter number of hours worked for employee %d: ", i);
        scanf("%f", &hours);

        // Initialize variables
        overtimeHours = 0;
        overtimePay = 0;
        normalPay = 0;

        // Calculate the overtime hours, normal pay, and overtime pay
        if (hours > STD_HOURS) {
            overtimeHours = hours - STD_HOURS;
            normalPay = STD_HOURS * wageRate;
            overtimePay = overtimeHours * wageRate * 1.5;
        } else {
            normalPay = hours * wageRate;
        }

        // Calculate the gross pay with normal pay and any additional overtime pay
        grossPay = normalPay + overtimePay;

        // Print out information on the current employee
        printf("\n\n------------------------------------------------");
        printf("\nClock#   Wage   Hours   OT     Gross\n");
        printf("------------------------------------------------");
        printf("\n%06d   %5.2f   %5.1f   %5.1f   %8.2f\n", 
               clockNumber, wageRate, hours, overtimeHours, grossPay);
    }
    
    return 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   0.0     0.00


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

Clock# Wage  Hours  OT      Gross
------------------------------------------------
526488  9.75  42.5   0.0     0.00


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

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


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

Clock# Wage  Hours  OT      Gross
------------------------------------------------
034645 12.25  45.0   0.0     0.00


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