0

I am making a program that involves adding time.
It involves adding a beginning time, duration which would lead to the result of an end time from the sum of beginning time and duration. I will illustrate the problem i am having below:
12:15 start time with a duration of 45 minutes should lead to the end time being: 13:00
I wish to display all the times afterwards.

int beginHour = 12
int beginMinute = 15;
int durationHour = 0;
int durationMinute = 45;
int endHour;
int endMinute;

The outcome should look like:
Starttime: 12:15
Duration : 0:45
Endtime: 13:00

However it looks like this:
Startime: 13:15
Duration: 0:45
Endtime: 13:00

My code that is doing this:

if(beginHour + durationMinute >= 60)
{
   ++endHour, endMinute = (beginMinute + durationMinute)%60; 
   endHour = beginHour;
}

I'd appreciate if someone could show me where I am going wrong?

Edited by Drakarus: Double posted accidentally

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Aranarth
0

It should be:

if(beginMinute + durationMinute >= 60)++endHour, endMinute = (beginMinute + durationMinute)%60;
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.