0

Hi again,
I have a small application that calculates time left over in a day after events.
The problem I have is that if either the starting time or ending time is 4.10 or 5.10 I get slightly incorrect answer.
Eg.
if the only event starts at 4 and ends at 4.10, it outputs that I have 23 hours and 51 minutes free (instead of 50 minutes)
Or if the event is 5.10 until 6, it outputs 23 hours and 9 minutes.

These are the only times that give incorrect answers.
I can post my code if its necessary, but was just wondering if this is a common problem easily overcome?

Thanks.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Moonrise_state
0

Ok, here is my method;

public int calculateMinsleft (Lecture other, Lecture other2, Lecture other3, Lecture other4){ //calculate minutes left
return (1440-(minutes+other.minutes+other2.minutes+other3.minutes+other4.minutes))-(((1440-(minutes+other.minutes+other2.minutes+other3.minutes+other4.minutes))/60)*60);
}

"minutes" are the duration of each lecture in minutes.

I just patched it up with an ugly while statement which will suffice, but I'd love to learn what's going on here.

Thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.