Professional Documents
Culture Documents
h>
#include <time.h>
#include <string.h>
#include <time.h>
int main()
{
int id;
time_t t;
struct tm *tm;
char clockin[100];
char clockout[100];
int choice;
char username[20];
char password[20];
float pay;
int counter = 0;
// continue program
printf("Please enter your ID to clock in: "); // Prompt user to enter ID to clock in
scanf("%d", &id);
strftime(clockin, 100, "%X", tm); // Format the time and store it in a string
printf("You have clocked in at %s\n", clockin); // Print the clocked-in time
printf("Please enter your ID to clock out: "); // Prompt user to enter ID to clock out
scanf("%d", &id);
strftime(clockout, 100, "%X", tm); // Format the time and store it in a string
printf("You have clocked out at %s\n", clockout); // Print the clocked-out time
// Calculate payroll based on hours worked and rate of pay per hour.
float hoursWorked = (float)(clockout - clockin) / 3600; // Calculate hours worked by
subtracting clocked-in from clocked-out times. Divide by 3600 for hours.
float rateOfPay = 10.00; // Set rate of pay per hour here. Can be changed as needed.
float payroll = hoursWorked * rateOfPay; // Calculate payroll by multiplying hours
worked by rate of pay per hour.
printf("Your total payroll is $%.2f\n", payroll); // Print total payroll amount here.
FILE *fp;
fp = fopen("clockin.txt", "a");
fprintf(fp, "%d %s %s $%f\n", id, clockin, clockout, payroll);
fclose(fp);