Hi, i'm having problem on the computation of working hours, regular pay, overtime and gross income... on a time-in and time-out of an employee for a week including holidays and overtime... please help on making it work.
e.g. of employee.txt
Name: kiroyzki
Code: A02-004
Level: 1
Salary/Day: 500/day
############################################
#include<conio.h>
#include<iostream.h>
#include<fstream.h>
#include<string.h>
main()
{
//Defining Variables
ofstream file2 ("dtr.txt");
ifstream file1 ("employee.txt");
int arrIn[5];
int arrOut[5];
char empCode[100];
int indx;
int empSalLevel;
int empRateDay;
char empName[100];
char *day[5]={"Monday","Tuesday","Wednesday","Thursday","Friday"};
int timeIn=0,timeOut=0,timeInDec=0,timeOutDec=0,dailyOver=0,dailyOTDelay=0;
int dailyTime=0,dailyLate=0,overIn=0,overOut=0,holiTime=0,holiLate=0;
double weeklyLate=0,weeklyTime=0,weeklyHoliLate=0,weeklyHoli=0,weeklyOver=0;
double weeklyOTDelay=0,regular=0,Holi=0,OT=0,overTimeIncome=0;
char covMonth[15],holiday;
char covDay[4];
char covYear[5];
double gross=0,totalWork=0;
char buffer[100];
int sagot=0;
clrscr();
//Read Employee Code from the employee.txt
cout<<"Enter Employee Code: ";
cin>>empCode;
while(!file1.eof()){
file1.getline(buffer,100);
sagot=strcmp(empCode,buffer);
if (sagot==0)
{
file1>>empName;
file1>>empSalLevel;
file1>>empRateDay;
cout<<"Name: \t\t"<<empName<<endl;
cout<<"Salary Level: \tLevel-"<<empSalLevel<<endl;
cout<<"Rate per Day: \t"<<empRateDay<<endl;
break;
}
}
file1.close();
//Daily Time Input
for (int ctr=0;ctr<5;ctr++){
//Time Format in Hundreds
cout<<day[ctr]<<endl<<"\tTime In: ";
cin>>timeIn;
arrIn[ctr]=timeIn;
cout<<"\tTime Out: ";
cin>>timeOut;
arrOut[ctr]=timeOut;
//Ask for Holiday and Overtime
cout<<"\tHoliday? y or n: ";
cin>>holiday;
cout<<"\tOvertime In: ";
cin>>overIn;
cout<<"\rOvertime Out; ";
cin>>overOut;
//Eliminating minutes
timeOut=timeOut/100;
timeOut=timeOut*100;
//Asking Holiday
if (holiday== 'y' || holiday=='Y'){
holiTime=timeOut-timeIn;
holiLate=timeIn%100;
}else{
dailyTime=timeOut-timeIn;
dailyLate=timeIn%100;
}
holiday='n';
dailyOver=overOut-overIn;
dailyOTDelay=overIn%100;
//Weekly Time Computations
weeklyLate=weeklyLate+dailyLate;
weeklyHoliLate=weeklyHoliLate+holiLate;
weeklyTime=weeklyTime+dailyTime;
weeklyHoli=weeklyHoli+holiTime;
weeklyOver=weeklyOver+dailyOver;
}
//saving time to dtr.txt
for(int a=0;a<=4;a++)
{
file2<<day[a]<<endl;
file2<<arrIn[a]<<endl;
file2<<arrOut[a]<<endl;
}
file1.close();
//Conversaion from Hundreds to Decimals
weeklyTime=weeklyTime+weeklyLate;
weeklyLate=weeklyLate/60*100;
weeklyTime=weeklyTime-weeklyLate;
weeklyTime=weeklyTime/100;
weeklyHoli=weeklyHoli+weeklyHoliLate;
weeklyHoliLate=weeklyHoliLate/60*100;
weeklyHoli=weeklyHoli-weeklyHoliLate;
weeklyHoli=weeklyHoli/100;
weeklyOver=weeklyOver+weeklyOTDelay;
weeklyOTDelay=weeklyOTDelay/60*100;
weeklyOver=weeklyOver-weeklyOTDelay;
weeklyOver=weeklyOver/100;
//Reading Coverage Date
cout<<"\nCoverage Date: ";
cin>>covMonth>>covDay>>covYear;
//Computing working hours
totalWork=weeklyOver+weeklyHoli+weeklyTime;
//Selecting Employee Name
cout<<"Name:\t\t\t"<<empName<<endl;
cout<<"Code:\t\t\t"<<empCode<<endl;
cout<<"Level:\t\t\t"<<empSalLevel<<endl;
cout<<"Rate per Day:\t\t"<<empRateDay<<endl;
cout<<"Total of work hours:\t"<<totalWork<<endl;
cout<<"Coverage Date:\t\t"<<covMonth<<" "<<covDay<<" "<<covYear<<endl;
//Computations of Regular Pay
regular=(empRateDay/9)*weeklyTime;
cout<<"Regular Income:\t\t"<<regular<<endl;
//Computations of Overtime Income
Holi=(empRateDay/9)*weeklyHoli;
OT=(empRateDay/9)*weeklyOver;
overTimeIncome=Holi+OT;
cout<<"Overtime Pay:\t\t"<<overTimeIncome<<endl;
//Computations of Gross Pay
gross=overTimeIncome+regular;
cout<<"Gross Income:\t\t"<<gross<<endl;
file2<<"Name:\t\t\t"<<empName<<endl;
file2<<"Code:\t\t\t"<<empCode<<endl;
file2<<"Level:\t\t\t"<<empSalLevel<<endl;
file2<<"Rate per Day:\t\t"<<empRateDay<<endl;
file2<<"Total works:\t\t"<<totalWork<<endl;
file2<<"Coverage Dte:\t\t"<<covMonth<<""<<covDay<<""<<covYear<<endl;
file2<<"Regular Income:\t\t"<<regular<<endl;
file2<<"Overtime Income:\t\t"<<overTimeIncome<<endl;
file2<<"Gross Income:\t\t"<<gross<<endl;
getch();
return 0;
}