Hi,
This program is menu driven with the user choosing the function they would like to run. The function prototype I am using is running but has a logical error I cannot solve. It is supposed to print a completion timetable: event #, max days for a task within the event and the total days for the project to complete. It is using a txt file to recieve the data.
when you run the function it is supposed to look like this when it prints to the screen:
event number max days
1 6
2 5
3 4
4 7
5 4
The maximum number of days to complete the project is 26 days.
The data it is processing is ( the * is what it should print after processing as above)
event task number of days
1 15 3
1* 27 6*
1 36 4
2* 15 5*
3* 18* 4*
3 26 1
4 15 2
4* 26 7*
4 27 7
5* 16 4*
etc
the tasks can happen at the same time therefore the program is supposed to recognize the largest amount of days per event and add all the largest ones together* for the maximum time for the project to finish.
Code:
void GetTotalDays(FILE *inFile)
{
int total = 0;
int CEvent, NEvent, TaskNum, NumDays, MaxDays;
{
fscanf(inFile, "%i %i %i", &CEvent, &TaskNum, &NumDays);
MaxDays=NumDays;
}
printf("Event #\t Max. Days");
while(fscanf(inFile, "%i %i %i ", & CEvent,&TaskNum, &NumDays) == 3)
{
if (CEvent == NEvent)
{
if (NumDays > MaxDays)
{
MaxDays=NumDays;
}
}
else
{
printf("\n%i\t %i\n ",CEvent, MaxDays);
CEvent = NEvent;
total = total+MaxDays;
MaxDays=NumDays;
}
}
printf("%i\t %i\n", CEvent,MaxDays);
printf("The maximum number of days for the project to completed in is %i days.", total);
}
I know that the issue is that it is printing the largest value for maxdays right away instead of comparing it to the next line. How do I distinguish the next event from the current event as well as the number of days from one line from the next?
[\tag]