Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I want my clock program to display the output as 00:00 instead it displays it as 0:0 even though I have used stream manipulators

So I made a sloppy clock program as an assignment. It works fine however I want the output to display each cout as "01:02", instead it displays "1:2", even though I think I have written all the right manipulators. This is my whole program.

#include <thread>
#include <chrono>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <stdlib.h>
using namespace std;
int main()
{
    cout << fixed << right;
    cout.fill(0);
    for (int m = 0; m < 59; m++)
    {
        for (int s = 0; s < 59; s++)
        {
            this_thread::sleep_for(
                chrono::seconds(1));
            system("cls");
            cout << setw(2) << m << ":";
            cout << setw(2) << s << endl;
        }
    }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are using the null character to fill (which is not visible).

cout.fill(0);

What you probably meant was to use the ASCII character 0, like this:

cout.fill('0');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading