#include <iostream>
using std::cout;
using std::endl;
using std::cin;
struct TIME
{
int seconds;
int minutes;
int hours;
};
void TimeDifference(struct TIME t1, struct TIME t2, struct TIME *diff);
int main()
{
struct TIME t1, t2, diff;
cout << "Write start time: hours, minutes, seconds: ";
cin >> t1.hours >> t1.minutes >> t1.seconds;
cout << "Write stop time: hours, minutes, seconds: ";
cin >> t2.hours >> t2.minutes >> t2.seconds;
TimeDifference(t1, t2, &diff);
cout << endl << "difference = " << diff.hours << ":"
<< diff.minutes << ":"
<< diff.seconds << endl;
return 0;
}
void TimeDifference(struct TIME t1, struct TIME t2, struct TIME *diff)
{
if (t2.seconds > t1.seconds)
{
t1.minutes--;
t1.seconds += 60;
}
diff->seconds = t1.seconds - t2.seconds;
if (t2.minutes > t1.minutes)
{
t1.hours--;
t1.minutes += 60;
}
diff->minutes = t1.minutes - t2.minutes;
diff->hours = t1.hours - t2.hours;
}
/*
run:
Write start time: hours, minutes, seconds: 13 18 23
Write stop time: hours, minutes, seconds: 16 15 12
difference = -3:3:11
*/