while (1) {
sleep(1000);
if (seconds == 60) {
minutes++;
seconds = 0;
} else {
seconds++;
}
if (minutes == 60) {
hours++;
minutes = 0;
} else {
minutes++;
}
if (hours == 24) {
hours = 0;
} else {
hours++;
}
if(seconds%2 !== 0) {
print(hours + ":" + minutes + ":" + seconds);
} else {
print(hours + " " + minutes + " " + seconds);
}
}
3 Responses
//
#include "stdafx.h"
#include "windows.h"
#include "iostream"
int main()
{
int minutes=0, seconds=0, hours=0;
while (1)
{
Sleep(1000);
system("cls");
seconds++;
if(seconds == 60)
{
minutes++;
seconds = 0;
}
if(minutes == 60)
{
hours++;
minutes = 0;
}
if(hours == 24)
{
hours = 0;
}
if(seconds % 2 != 0)
{
std::cout << hours << " " << minutes << " " << seconds;
}
else
{
std::cout << hours << ":" << minutes << ":" << seconds;
}
}
return 0;
}
Write a comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.