A simple clock in C++

As stated in the previous post I made two version of this clock on in C and one in C++ this is the C++ version.

#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <ctime>



using namespace std;

int main(int argc, char** argv) {
A:

    time_t now = time(0);

    tm *ltm = localtime(&now);

    cout << "Day: " << ltm->tm_mday << endl;
    cout << "Month: " << 1 + ltm->tm_mon << endl;
    cout << "Year:" << 1900 + ltm->tm_year << endl << endl;
    cout << std::setfill('0') << std::setw(2) << "Time: " << 0 + ltm->tm_hour << ":";
    cout << std::setfill('0') << std::setw(2) << 0 + ltm->tm_min << ":";
    cout << std::setfill('0') << std::setw(2) << 0 + ltm->tm_sec << endl;
    cout << "The time is correct as long as your system is correct\n";

    sleep(1);
    system("clear");

    goto A;
}

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *