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;

}

That's a lot of code to look through. Could you pinpoint what's going wrong - what result are you getting, what result do you expect?

Have you tried walking through the code, following sample data and calculating by hand what each statement does? Compare what you expect to what the code computes.

well the problem is that it could not compute the total hours of work for a week according to the time-in time-out an employee inputs per day... the result is always 0... it could not also compute the weekly regular day salary and gross income according to their salary/day and the Overtime, holiday work hours result always 0... e.g Overtime and holidays are double pay

well on the expected result.... e.g. from day1[Monday] to day5[Friday] the employee time-in[8:00am] time-out[5:00pm] the result total work hours[40] on the salary/day [500/9]* weekly Time-In [40] result regular pay[2500] this is on an employee who regularly go's to work... well some are late and to early timing-out.... that will loss a percent in weekly salary and on an Overtime and Holiday work regular pay per day is doubled

For starters, your reading loop has a problem.

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

Search this forum for discussion on why using !file.eof( ) is not a good choice. I won't repeat it all here.

It would help if you gave the data file example EXACTLY as you use it, not with labels, and not out of order!

How is time to be entered? It's not clear in your comments or code.

In most cases I'm familiar with, one does not enter overtime hours directly - the program computes overtime based on in/out time exceeding the standard.

8am to 5pm is 9 hours.

That said, I entered 5 days with start 800 quit 1600 holiday no overtime start stop 0 and 0, it gave 40 hours worked and a total pay of 2200.

5 days of 800-1700 work, no holiday or overtime, total hours 45 (correct) pay 2475.

I suspect you have a problem with dividing integers and losing some fractional time. Remember, int / int = int, with remainder discarded. 17 / 3 = 5 (where'd the 2 leftover go?) Should you instead be doing all storage and calculations in doubles? Check your logic.

In most cases I'm familiar with, one does not enter overtime hours directly - the program computes overtime based on in/out time exceeding the standard.
**********************************************************
could you show me how to code it?? Thanks i appreciate it

In most cases I'm familiar with, one does not enter overtime hours directly - the program computes overtime based on in/out time exceeding the standard.
**********************************************************
could you show me how to code it?? Thanks i appreciate it

It could be handled in one of two ways. Either determine if a single day's hours exceed the standard day, add the excess to overtime total. At end of week, calculate base pay and overtime pay.

Other way is just total up all the work hours of the week. At end of week, any hours over the base amount is overtime.

For example, Joe's job is based on a 40 hour workweek, and he's paid 20 dollars an hour, and time and half for overtime.

Week one he works exactly 40 hours, pay is 20 * 40 = 800.
Week two he works 45 hours. So he's paid 20 *40 (base pay) plus 1.5 * 20 * 5 for overtime hours. 800 + 150 = 950.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.