I am new to C++ and working on an assignment. Below is what I have come up with so far and seems to be working. I am at the last part and have spent many hours trying to figure this out without any luck. I need to add the total hours and minutes at the bottom of my time sheet. The minutes need to add up properly with the hours. This meaning I can not have over 59min in the minutes column. I am not sure how to tell the program to calculate the data from the file. Any help would be greatly appreciated. This is driving me bonkers!! :) Here are the instructions and .txt file I am working with. I thank you greatly for any help.
www.tier1studio.com/dowloads/TimesheetSpring12.pdf
www.tier1studio.com/dowloads/Timesheet.txt
inFile >> date >> hours >> minutes;
while(inFile)
{
if (minutes>59) //detects if there are more than 59 minutes
{
hours = minutes / 60; //convert all minutes to hours
overflowhours = floor(hours); //round hours down
minutes = (hours - overflowhours) * 60; //get the difference that was lost with rounding and convert it to minutes
hours = overflowhours; //set hours to a whole number
}
cout << left << setw(35) << date <<setw(25) << hours << right << setw(7) << minutes << endl;
totalmin = totalmin + minutes; //add minutes to a total each time this statement runs
totalhours = totalhours + hours; //add hours to an overall total each time this statement runs
inFile >> date >> hours >> minutes;
}
inFile.close();
The part in bold is what you would add, of course you would declare the variables and set them = 0 at the top. And then you would output the final total after your while statement is finished.