Good day everyone.
I am back from some previous months of extensive schoolwork.
I am creating now a payroll application,
but I think there's something wrong in my code,
because it created an output that's not my intended output.
Wait, guys, I'm confused. Is this appropriate for a C forum although
I use C language in my code? Because I'm using a C++ Compiler,
my assumption is to post it here in C Forum.
Well it's okay if someone moves this thread in C++ area.
I'm just currently a newbie in such forums.
Here's my code:
/* My Payroll System /
/----------------------------------------------*/
// Start of file.
//Include Libraries
//Defines Functions
//Pointer Chars for Time-in and Time-out
char *day[5]={"Monday","Tuesday","Wednesday","Thursday","Friday"};
//Variables with Arrays
int time_in[2];
int time_out[2];
char empna[30];
char empmidna[15];
char emplastna[30];
char empcode[30];
char date[30];
char min[5];
char searchempcode[30];
//Variables
int found, x;
int level;
int twhrs=0;
float rinc;
float srate=0;
//File Operations
FILE *empfile;
FILE *dtrfile;
//SUBROUTINE: Prints the current time (Optional)
void printtime()
{
struct time t;
gettime(&t);
{
g(60,24);p("[ %2d:%02d:%02d.%02d ]\n",
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
}
}
//SUBROUTINE: Header Bar Message (Optional)
void showmsg()
{
g(22,2);p("Spectre Reviewals Examination Company");g(25,3);p("Assessment : Payroll System");
g(1,4);p("[------------------------------------------------------------------------------]\n");
}
//SUBROUTINE: Read File Operations
void readfile()
{
fs(empfile, "%s", &empna);
fs(empfile, "%s", &empmidna);
fs(empfile, "%s", &emplastna);
fs(empfile, "%s", &empcode);
fs(empfile, "%d", &level);
}
//SUBROUTINE: Write File Operations
void writefile()
{
showmsg();
printtime();
fp(dtrfile, "%s : ", empcode);
for(x=0;x<5;x++)
{
fp(dtrfile, " %d%s ", time_in[x], min[x]);
fp(dtrfile, " %d%s ", time_out[x], min[x]);
}
}
//SUBROUTINE: File and Program Process Operations
void process_data()
{
clrscr();
showmsg();
printtime();
g(13,6);p("Enter the login and logout time for the days described.");
g(19,7);p("Clock times must be in military format.");
g(22,8);p("(Example: Eight o' clock = 0800) \n");
for(x=0;x<5;x++)
{
p("\n Time in for the day of %s: ", day[x]);
s("%d%s",&time_in[x],&min[x]);
p(" Time out for the day of %s: ", day[x]);
s("%d%s",&time_out[x],&min[x]);
twhrs=(time_out[x]-time_in[x]-1)+twhrs;
}
clrscr();
showmsg();
printtime();
g(21,6);p("Enter your Payroll Coverage Date.");
g(18,7);p("Date must be valid and on the date of work. \n");
p("\n Payroll Coverage Date: ");
scanf("%c",date);
gets(date);
{
if(level==1)
srate=350.00;
else if(level==2)
srate=450.00;
else if(level==3)
srate=550.00;
else
srate=750.00;
}
rinc=(srate/8)*twhrs;
clrscr();
showmsg();
printtime();
g(21,5);p(" Program Output and Employee Details ");
g(21,6);p("_____________________________________\n");
p("\n[Company Employee Information]\n");
p(" Employee Name: %s %s %s\n",empna,empmidna,emplastna);
p(" Employee Code: %s\n",empcode);
p(" Salary Level: %d\n\n",level);
p("\n[Employee's Work Rate Information]\n");
p(" Salary Rate: %.02f\n",srate);
p(" Coverage Date: %s\n",date);
p(" Total Hours Worked: %d\n\n",twhrs);
p(" \nREGULAR WORKING INCOME: %.02f\n",rinc);
g(27,23);p("Press a key to terminate...");
}
//MAIN: The Main Program Operations
main()
{
clrscr();
showmsg();
printtime();
empfile=fopen("employee.txt","rt");
dtrfile=fopen("dtr.txt","wt");
g(27,6);p("Search for Employee Code\n");
p("\n Please enter Employee Code: ");
s("%s",&searchempcode);
readfile();
found=0;
while(!feof(empfile)&& found==0)
{
if(strcmp(empcode,searchempcode)==0)
{
clrscr();
showmsg();
printtime();
g(24,6);p("Employee Company Information");
g(27,7);p("[Code found: %s ]\n",empcode);
p("\n Employee Name: %s %s %s\n",empna,empmidna,emplastna);
p(" Employee Code: %s\n",empcode);
p(" Salary Level: %d\n",level);
p("\n\n Press any key to continue...");
getch();
process_data();
writefile();
found=1;
}
else
{
readfile();
clrscr();
showmsg();
printtime();
g(24,12);p("Sorry, we have found no records.");g(26,14);p("Please try again later.");
}
}
fclose(empfile);
fclose(dtrfile);
getch();
}
// end of file.
It displayed my program output very correctly,
I can provide screenshots of my screen output if requested.
The only thing that does my code incorrectly is my file output.
This is the result of writing into a new file (the output).
I attached the Notepad file DTR.TXT:
DTR.TXT
If needed for analyzation, here's my Notepad read file EMPLOYEE.TXT:
employee.txt
Help is really appreciated.
Please accept my "Thank you very much" for those that may help. :)