Below is my code for a beginning type project. I am asking for help with defining constants. What other constants can I include or what variables can I change to constants. I have muddled over this for a while and would like some input from my fellow c programmers. Also, this is a project that was to be written within the confines of the first few chapters of a text book. Therefor, there is no advanced code included in my code. So please do not post any other ways in which I could have written it more efficiently unless it directly relates to defining constants.
Thanks for your Help!!!
Code:
#include <stdio.h>
#define STD_HOURS 40.0 /*standard hours per work week */
int main(void)
{
long clock_num; /* employee clock number */
int counter; /* counter to tell for loop where to begin and end */
float gross; /* weekly gross pay (wage * hours) */
float hours; /* number of hours worked per week */
int num_of_employees; /* query user for number of employees */
float overtime = 0.0; /* overtime hours worked initialized to 0.0 */
float overtime_pay; /* overtime pay is paid as time and a half (overtime * ( wage + (wage/2))) */
float wage; /* hourly wage */
/* Prompt explaining program and asking for user input */
printf("This is a program to calculate weekly gross pay.\n");
printf("You will now be prompted to enter employee data.\n\n");
printf("Please enter the number of employees to calculate weekly gross pay for: \n");
scanf("%i", &num_of_employees);
/* for loop to cycle through the number of employees and gather employee information */
for (counter = 1; counter <= num_of_employees; counter++)
{
printf("\n\nEnter clock number for employee: ");
scanf("%li", &clock_num);
printf("Enter hourly wage for employee: ");
scanf("%f", &wage);
printf("Enter the number of hours the employee worked: ");
scanf("%f", &hours);
if (hours > STD_HOURS)
{
overtime = hours - STD_HOURS;
overtime_pay = overtime * (wage + (wage / 2));
gross = wage * STD_HOURS + overtime_pay; /*calculate gross pay to include overtime */
}
else
{
gross = wage * hours; /* calculate gross pay if condition is false */
}
/* Create table to display employee information */
printf("\n------------------------------------------------\n");
printf("Clock# Wage Hours OT Gross\n");
printf("------------------------------------------------\n\n");
/* Print employee information into created table */
printf("%06li %5.2f %5.1f %5.1f %7.2f\n", clock_num, wage, hours, overtime, gross);
}
getchar(); /* Get character before exit */
return(0); /* success */
}