Watch

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

This doesn't works for c++, there are a lot of erros and I fixed them lol but thanks for the idea
// ConsoleApp// operacionesconmatrices.cpp: define el punto de entrada de la aplicación de consola.
//

#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;
}
@Victoria R González Hello Victoria, I made this snippet without an editor/debugger just to help a friend of mine who is learning programming to get in the right mindset. It wasn't intended for public consumption but thank you for your helpful comment. Perhaps it will help anyone who stumbles upon this.

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.