C++

A helpful clock!

fork
loading
Files
  • main.cpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

using namespace std;

string currentHour;
string currentMinute;

const string currentDateTime() {
    time_t now = time(0);
    struct tm tstruct;
    char buf[80];
    tstruct = *localtime(&now);
    strftime(buf, sizeof(buf), "%X", &tstruct);
    currentHour = "";
    currentMinute = "";
    currentMinute += buf[3];
    currentMinute += buf[4];
	currentHour += buf[0];
	currentHour += buf[1];
    return buf;
}

int main() {
    cout << "Welcome to the Clock program created by Ryan the Donut!";
    sleep(2);
    cout << endl << endl << "This program used to be in Python 3, but it barely worked.";
    sleep(4);
    cout << endl << endl << "Now it's in C++ and it works great!";
    sleep(3);
    currentDateTime();
    cout << endl << endl << "The current server time: " << currentHour << ":" << currentMinute << endl;
}