You are on page 1of 4

#include <stdio.

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;

while (counter < 3)


{
printf("Please enter your username: ");
scanf("%s", username);
printf("Please enter your password: ");
scanf("%s", password);

if (strcmp(username, "Admin") == 0 && strcmp(password, "Sweettooth") == 0)


{
printf("Login successful!\n");
break;
}
else
{
printf("Incorrect username or password. Please try again.\n");
counter++;
}
}
if (counter == 3)
printf("Too many failed attempts.\n");

printf("Username and password accepted. Program will now continue.\n\n");

// continue program

printf("1. Manager Portal/Login\n");


printf("2. Employee Portal/Login\n");
printf("Select either 1 or 2\n");
scanf("%d", &choice);

printf("Please enter your ID to clock in: "); // Prompt user to enter ID to clock in
scanf("%d", &id);

t = time(NULL); // Get current time


tm = localtime(&t); // Store it in a structure

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);

t = time(NULL); // Get current time


tm = localtime(&t); // Store it in a structure

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);

printf("Do you want to start over? (Y/N): ");


char answer;
scanf(" %c", &answer);
if (answer == 'Y' || answer == 'y')
main();
else
printf("Program ending.\n");
return 0;
}

You might also like