overloading operator

I need to find journey time (arrivalTime - departureTime). I have Time class with minutes and hours. and Flights class that arrivalTime and departureTime declared like this:

1
2
  flight1.departureTime = Time (6, 0);
    flight1.arrivalTime = Time (8, 55);


then I overloaded - operator

1
2
3
4
5
6
7
8
Time Time::operator-(Time num){
    Time newTime (num.hours - this->hours, num.minutes - this->minutes);
    if (newTime.minutes < 0){
        newTime.minutes = 60 + newTime.minutes;
        newTime.hours --;
    }
    return newTime;
}


and called it in main:

1
2
3
Time time1 = flight1.arrivalTime - flight1.departureTime;

    time1.printTime();


and i get 65534:65481

instead of 02:55

any idea where i went wrong?
If hours and minutes are unsigned integers they will never be less than zero.
so obvious thanks
Topic archived. No new replies allowed.