I have this project and I'm done with it .. But I have a logical error .. When it comes to the print part it prints only the last name and the last calculated average .. I couldn't figure out the error
The program is created to enter employee name and their worked hours during the year and then calculating their averages ,. And at the end it should print a report with the name I entered and the averages ..
The program goes this way:
Pleas enter employee name: hfgjd
Please enter the worked hours: 2
Please enter worked hours:2
please enter worked hours: 0
The average is:2
Would you like to continue? (Y/N) .. N
"The report part"
The class:
Code:
classEmployee
{
privatestring employeeName;
privatedouble[] workHours = newdouble[12];
privatebool validIndex = true;
privatedouble avgWorkedHours;
publicstring getEmployeeName()
{
return employeeName;
}
publicvoid setEmployeeName(string name)
{
employeeName = name;
}
publicdouble getWorkHours(int index)
{
return workHours[index];
}
publicvoid setWorkHours(double hours, int index)
{
if (index < 0 || index > 12)
{
Console.WriteLine("Wrong Entry!");
validIndex = false;
}
else
{
workHours[index] = hours;
}
}
publicbool getValidIndex()
{
return validIndex;
}
publicdouble getAvgWorkedHours()
{
return avgWorkedHours;
}
publicvoid setAvgWorkedHours(double average)
{
int max = 0;
double sum = 0;
for (int i = 0; i < 12; i++)
{
if (workHours[i] == 0)
{
max = i;
break;
}
else
{
sum += workHours[i];
max = i;
}
}
if (max > 0)
average = sum / max;
avgWorkedHours = average;
}
}
