fork download
  1. //*******************************************************
  2. //
  3. // Homework: 3
  4. //
  5. // Name: Blake Shetler
  6. //
  7. // Class: C Programming, Fall 2024
  8. //
  9. // Date: 09/29/2024
  10. //
  11. // Description: Program which determines gross pay
  12. // and outputs are sent to standard output (the screen).
  13. //
  14. // Non file pointer solution
  15. //
  16. //********************************************************
  17.  
  18. #include <stdio.h>
  19.  
  20. //declare constants
  21. #define STD_HOURS 40.0 // 40 hours worked per week is standard
  22. #define QUANTITY 5 // 5 employees will be processed in this program
  23. #define OT_DIFF 1.5 // OT differential is normal pay rate times 1.5
  24.  
  25. int main()
  26. {
  27. //declare variables
  28. int clock_number; // employee's ID or clock number
  29. float wage_rate; // employee's hourly rate
  30. float hours_worked; // number of hours employee worked for that week
  31. float gross_pay; // employee's gross pay for the given week
  32. float reg_pay; // regular hourly rate
  33. float overtime_pay; // pay rate for overtime hours
  34. int idx; // index to be used for loop
  35.  
  36. //print program header
  37. printf("\t ~~~~~~~~ Pay Calulator ~~~~~~~~\n");
  38.  
  39. //Loop to prompt user to enter clock number, hourly wage, and hours worked for each employee
  40. {
  41. for (idx = 0; idx < QUANTITY; ++idx)
  42. {
  43. printf("\nEnter employee's clock number: \n"); //enter clock number
  44. scanf("%d", &clock_number);
  45.  
  46. printf("Enter hourly wage for employee: \n"); //enter hourly rate
  47. scanf("%f", &wage_rate);
  48.  
  49. printf("Enter the number of hours the employee worked this week: \n"); //enter hours
  50. scanf("%f", &hours_worked);
  51.  
  52. //calucation for gross pay
  53. if (hours_worked <= STD_HOURS) //if employee worked standard or less hours
  54. {
  55. gross_pay = wage_rate * hours_worked; //gross pay will be calculated normally
  56. }
  57. else //otherwise, employee worked overtime
  58. {
  59. overtime_pay = (hours_worked - STD_HOURS) * wage_rate * OT_DIFF;
  60. reg_pay = (STD_HOURS * wage_rate);
  61. gross_pay = overtime_pay + reg_pay; // gross pay will be OT pay plus regular pay
  62. }
  63.  
  64. //printing out results
  65. printf("\n\t=========================\n");
  66. printf("\tClock# Wage Hours Gross\n");
  67. printf("\t=========================\n");
  68.  
  69. printf("\t%06i %.2f % 2.1f % 6.2f \n", clock_number, wage_rate,
  70. hours_worked, gross_pay);
  71. } // end of the loop
  72. }
  73. return(0);
  74. } //end of main function
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 Calulator ~~~~~~~~

Enter employee's clock number: 
Enter hourly wage for employee: 
Enter the number of hours the employee worked this week: 

	=========================
	Clock# Wage  Hours Gross
	=========================
	098401 10.60  51.0  598.90 

Enter employee's clock number: 
Enter hourly wage for employee: 
Enter the number of hours the employee worked this week: 

	=========================
	Clock# Wage  Hours Gross
	=========================
	526488 9.75  42.5  426.56 

Enter employee's clock number: 
Enter hourly wage for employee: 
Enter the number of hours the employee worked this week: 

	=========================
	Clock# Wage  Hours Gross
	=========================
	765349 10.50  37.0  388.50 

Enter employee's clock number: 
Enter hourly wage for employee: 
Enter the number of hours the employee worked this week: 

	=========================
	Clock# Wage  Hours Gross
	=========================
	034645 12.25  45.0  581.88 

Enter employee's clock number: 
Enter hourly wage for employee: 
Enter the number of hours the employee worked this week: 

	=========================
	Clock# Wage  Hours Gross
	=========================
	127615 8.35  0.0   0.00