Help with Clock

im not having a problem with my code i just need to know how to have my clock say 1:05 instead of 1:5 when i subtract starting minutes from ending minutes.
When i find the difference between 4:30 and 3:15 it gives the correct 1:15 time elapse i just need the numbers under 10 to have a zero infront of it.

Thanks
A combination of the setw and setfill functions in the <iomanip> header will help in this regard.

http://www.cplusplus.com/reference/iostream/manipulators/setw/
http://www.cplusplus.com/reference/iostream/manipulators/setfill/

And of course, there's always the obvious:

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

void printSeconds(unsigned int seconds)
{
    if(seconds < 10)
    {
        cout << "0";
    }
    cout << seconds;
}
Last edited on
Topic archived. No new replies allowed.