Does anybody know how to make a program that calculates your work hours? I tried this code, but it's going all wrong.
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
#include<time.h>
char* timein[5], timeout[5], p;
int totaltime, ticktock, hour, minute, rate;
FILE* f;
int main(){
clrscr();
CreateTimeFile();
GetTimes();
DisplayFinalInfo();
getch();
}
CreateTimeFile(){
f = fopen("time.txt","w");
fclose(f);
}
GetTimes(){
f = fopen("time.txt","a");
printf("\nEnter time in 24-hour format. \nWARNING: An error at any point in the input will result in needing to repeat the process.\nEnter time-in for Monday: ");
scanf("%c",&timein);
ValidateTimeIn();
printf("\nEnter time-out for Monday: ");
scanf("%c",&timeout);
ValidateTimeOut();
AppendTimes();
printf("\nEnter time-in for Tuesday: ");
scanf("%c",&timein);
ValidateTimeIn();
printf("\nEnter time-out for Tuesday: ");
scanf("%c",&timeout);
ValidateTimeOut();
AppendTimes();
printf("\nEnter time-in for Wednesday: ");
scanf("%c",&timein);
ValidateTimeIn();
printf("\nEnter time-out for Wednesday: ");
scanf("%c",&timeout);
ValidateTimeOut();
AppendTimes();
printf("\nEnter time-in for Thursday: ");
scanf("%c",&timein);
ValidateTimeIn();
printf("\nEnter time-out for Thursday: ");
scanf("%c",&timeout);
ValidateTimeOut();
AppendTimes();
printf("\nEnter time-in for Friday: ");
scanf("%c",&timein);
ValidateTimeIn();
printf("\nEnter time-out for Friday: ");
scanf("%c",&timeout);
ValidateTimeOut();
AppendTimes();
fclose(f);
/* ComputeSalary(); */
/* DisplayTime(); */
}
ValidateTimeIn(){
if (timein[0] > 2 || timein[3] > 5){
printf("Input Error! Restarting input process.\n");
GetTimes();
}
if (timein[0] = 2 && timein[1] > 3){
printf("Input Error! Restarting input process.\n");
GetTimes();
}
}
ValidateTimeOut(){
if (timeout[0] > 2 || timeout[3] > 5){
printf("Input Error! Restarting input process.\n");
GetTimes();
}
if (timeout[0] = 2 && timeout[1] > 3){
printf("Input Error! Restarting input process.\n");
GetTimes();
}
}
AppendTimes(){
fprintf(f,"%s %s|",timein, timeout);
AddToTotalTime();
}
AddToTotalTime(){
/*-convert timein and timeout to time-*/
p = timeout;
atoi(p) = hour;
while (*p){
if (*p++ == ':')
atoi(p) = minute;
}
timeout = (hour * 60) + minute;
p = timein;
atoi(p) = hour;
while (*p){
if (*p++ == ':')
atoi(p) = minute;
}
timein = (hour * 60) + minute;
ticktock = timeout - timein;
totaltime += ticktock;
}
DisplayFinalInfo(){
hour = totaltime / 60;
minute = totaltime % 60;
printf("Total Work Time: %i Hours and %i Minutes\n", hour, minute);
}
I know I'm doing plenty of mistakes here. I just don't know what exactly. And no, I'm not supposed to work it in a different program like C#.