'How to include a leading zero when converting seconds to minutes and the remainder is less than 10 seconds?

My function turns seconds to minutes. The problem is, if I have a number where the remainder is less than 10, it will just give give me remainder without a 0 before the remainder.

For example,

  • 368 seconds would just turn to 6:8
  • 360 would turn to 6:0
  • 361 to 6:1

I would like

  • 368 seconds to turn to 6:08
  • 360 to 6:00
  • 361 to 6:01
void toMinutesAndSeconds(int inSeconds, int &outMinutes, int &outSeconds) {
    outMinutes = inSeconds / 60;
    outSeconds = inSeconds % 60;
}

I'm outputting to a text file.

c++


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source